Your employer has asked you to help define a brand new employee class. An employ
ID: 3575598 • Letter: Y
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 is an example employee: Emp1 name: "Peter" age: 25 timeEmployed: 18 salary: 50000.00 (yearly) A. 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. B. Write setters and getters for the fields C. Write a constructor which takes a name, age, salary, but sets the timeEmployed to 0. D. 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
import java.util.*;
import java.lang.*;
import java.io.*;
class Employee
{
private String name;
private int age;
private int timeEmployedMonths;
private double salary;
public Employee(Employee Emp1) //Copy constructor
{
this.name = Emp1.name;
this.age = Emp1.age;
this.timeEmployedMonths = Emp1.timeEmployedMonths;
this.salary = Emp1.salary;
}
public void setName(String name) //set and get methods
{
this.name = name;
}
public String getName()
{
return name;
}
public void setAge(int age)
{
this.age = age;
}
public int getAge()
{
return age;
}
public void setTimeEmployedMonths(int timeEmployedMonths)
{
this.timeEmployedMonths = timeEmployedMonths;
}
public int getTimeEmployedMonths()
{
return timeEmployedMonths;
}
public void setSalary(double salary)
{
this.salary = salary;
}
public double getSalary()
{
return salary;
}
public Employee(String name,int age,double salary) //parameterized constructor
{
this.name = name;
this.age = age;
this.salary = salary;
this.timeEmployedMonths = 0; //time employed =0
}
public double payOut(int timeEmployedWeeks)
{
double amount;
amount = (salary*timeEmployedWeeks)/56;
setTimeEmployedMonths(timeEmployedWeeks/4);
return amount;
}
}
class TestEmployee
{
public static void main (String[] args)
{
Employee Emp1 = new Employee("Peter",25,5000.00);
int months = 18;
int weeks = months*4;
System.out.println("Your Employer ows you $"+Emp1.payOut(weeks));
System.out.println("Number of months Employed : "+Emp1.getTimeEmployedMonths());
}
}
output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.