Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

java question! Your employer has asked you to help define a brand new employee c

ID: 3576229 • Letter: J

Question

java question!

Your employer has asked you to help define a brand new employee class. An employee is meant to have the following properties, an age, a salary, a name, and a value which tracks how many months they have been employed. Here Ls an example employee: Emp1 name: " Peter" age: 25 timeEmployed: 18 salary: 50000.00 (yearly) Write a default constructor which sets the employee's fields to match Emp1. Given the spec above, it is your job to decide the type of each field. Write setters and getters for the fields Write a constructor which takes a name, age, salary, but sets the timeEmployed to 0. In order to keep people around your employer has to pay people. Although unfortunate, people have to eat, apparently. Your job is to write some code which figures out how much your employer owes the employee. Your employer is pretty bad at paying people though, so it might have been a few weeks! Your employer only updates the total number of weeks worked when he pays you. Write a function payout() which accepts the total weeks you've worked, calculates the amount you're owed, updates your weeks worked in total, and returns what you're owed.

Explanation / Answer

Employee.java

public class Employee {
  
   //Declaring instance variables
   private String name;
   private int age;
   private double timeEmployed;
   private double salary;
  
   //Declaring a static variable
   static int count=0;
     
     
   //Zero argumented constructor
   public Employee() {
      
       //Setting the default values
       this.name = "Peter";
       this.age = 25;
       this.timeEmployed = 18;
       this.salary = 50000;

   }

   //Parameterized constructor
   public Employee(String name, int age, double salary) {
       super();
       this.name = name;
       this.age = age;
       this.timeEmployed = 0;
       this.salary = salary;
   }

   //Setters and getters
   public String getName() {
       return name;
   }

   public void setName(String name) {
       this.name = name;
   }

   public int getAge() {
       return age;
   }

   public void setAge(int age) {
       this.age = age;
   }

   public double getTimeEmployed() {
       return timeEmployed;
   }

   public void setTimeEmployed(double timeEmployed) {
       this.timeEmployed = timeEmployed;
   }

   public double getSalary() {
       return salary;
   }

   public void setSalary(double salary) {
       this.salary = salary;
   }


   //This method calculates how much amount employer owes to employee
   public double payput(int totalWeeks) {
       //Calculating the amount
       double salaryOwed = totalWeeks * getSalary() / 48;
      
       //Updating the time employed
       timeEmployed += (double) totalWeeks / 4;
       return salaryOwed;
   }

   //toString() method is used to display the contents of an object inside it.
   @Override
   public String toString() {
      
       return " Employee#"+(++count)+" Name=" + name + " Age=" + age + " TimeEmployed="
               + timeEmployed + " Salary=" + salary;
   }
  

}

__________________________

EmployeeTest.java(This class contains main() method .So we have to run this class to execute out program.)

public class EmployeeTest {

   public static void main(String[] args) {
      
       //Creating Employee Class object
       Employee emp1=new Employee();
      
       //Displaying the contents of the Employee class object
       System.out.println(emp1.toString());
      
       //Creating Employee Class object
       Employee emp2=new Employee("Williams",22,90000);
      
       //Displaying the contents of the Employee class object
       System.out.println(emp2.toString());
      
       //Displaying the how much amount the employer owes
       System.out.println("Salary Owed ="+emp2.payput(24));
      
       //Creating Employee Class object
       Employee emp3=new Employee("Johnson",26,40000);
      
       //Displaying the contents of the Employee class object
       System.out.println(emp3.toString());
      
       //Displaying the how much amount the employer owes
       System.out.println("Salary Owed ="+emp3.payput(36));


   }

}

________________________

Output:


Employee#1
Name=Peter
Age=25
TimeEmployed=18.0
Salary=50000.0

Employee#2
Name=Williams
Age=22
TimeEmployed=0.0
Salary=90000.0
Salary Owed =45000.0

Employee#3
Name=Johnson
Age=26
TimeEmployed=0.0
Salary=40000.0
Salary Owed =30000.0

_____________Thank You