a pastebin project

Exercise 3.10

  1. public class Employee
  2. {
  3.         private double monthlySalary=0.0f;
  4.         private String firstName="someone",lastName="someone";
  5.  
  6.         public Employee(String firstName,String lastName,Double monthlySalary)
  7.         {
  8.                 this.firstName=firstName;
  9.                 this.lastName=lastName;
  10.                 this.monthlySalary=monthlySalary;
  11.         }
  12.  
  13.         public double getmonthlySalary()
  14.         {
  15.                 if (monthlySalary<0)
  16.                 {
  17.                         return 0.0f;
  18.                 }
  19.                 else
  20.                 {
  21.                         return monthlySalary;
  22.                 }
  23.         }
  24.  
  25.         public String getlastName()
  26.         {
  27.                 return lastName;
  28.         }
  29.  
  30.         public String getfirstName()
  31.         {
  32.                 return firstName;
  33.         }
  34. }
  35.  
  36. /* Another class*/
  37. public class EmployeeTest
  38. {
  39.         public static void main(String argv[])
  40.         {
  41.                 Employee Justin=new Employee("Chan","Siu Ming",8000.0);
  42.                 Employee Hoyin=new Employee("Chan","Tai Ming",10000.0);
  43.                 System.out.printf("Justin yearly salary is $%.1f.\n" , (Justin.getmonthlySalary()*12));
  44.                 System.out.printf("Hoyin yearly salary is $%.1f.\n" , (Hoyin.getmonthlySalary()*12));
  45.                 System.out.println("After 10% raise!!");
  46.                 System.out.printf("Justin yearly salary is $%.1f.\n" , (Justin.getmonthlySalary()*12*1.1));
  47.                 System.out.printf("Hoyin yearly salary is $%.1f.\n" ,(Hoyin.getmonthlySalary()*12*1.1));
  48.         }
  49.  
  50. }

advertising

Create a Paste

Please enter your new post below (or upload a file instead):





Please note that information posted here will not expire by default. If you want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords.

fantasy-obligation