Can someone please write this program in Java? Thank you.
Create an Employee class as per the following specifications:
-three private instance variables: firstName (String), lastName(String), and salary (double)
-a single constructor with three arguments: the first name, the last name and the salary. In the constructor, initialize the instance variables with the provided parameter values.
-get and set methods for each of the instance variables.
-A computation method, calculateSalary, that takes the percent raise as a decimal value for its argument. The method returns the new salary using the calculation: salary + salary * raise%
-A toString method to return a string containing all information stored about the employee
Using the Employee class as a parent, write a child class called Manager that inherits all methods and attributes from Employee plus contains:
-An attribute of bonus (double)
-Methods that set and get the bonus
-An appropriate constructor that will set all instance variables
-An overridden computation method, calculateSalary, that takes the percent raise as a decimal value as its argument. The method returns the new salary using the calculation: salary + salary * raisepercent + bonus
-A toString method to return a string containing all information stored about the manager.
In another class, create a driver program that will:
-Create an employee object for Bob Smith who has a current salary of $45,000.
-Create a manager object for Sally Jones who has a current salary of $65,000 and a bonus of $6,500.
-Set Bob’s salary to the new calculated salary for next year based on giving him a 3% raise.
-Set Sally’s salary to the new calculated salary for next year based on giving her a 5% raise.
-Use the appropriate toString methods for Bob and Sally to output their new information to the user.
Expert Answer
Employee.java
public class Employee {
private String firstName ;
private String lastName;
private double salary;
public Employee(String firstName, String lastName, double salary) {
super();
this.setFirstName(firstName);
this.setLastName(lastName);
this.setSalary(salary);
}
public double calculateSalary(double raise) {
setSalary(getSalary()+ getSalary() * raise/100);
return getSalary();
}
public String employeedetails() {
return getFirstName().toString()+ getLastName().toString()+ Double.toString(getSalary()) ;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
——————————————————————————————————–
Manager.java
public class Manager extends Employee {
private double bonus;
public Manager(String firstName, String lastName, double salary, double bonus) {
super(firstName, lastName, salary);
this.bonus = bonus;
}
public double getBonus() {
return bonus;
}
public void setBonus(double bonus) {
this.bonus = bonus;
}
public Manager(String firstName, String lastName, double salary) {
super(firstName, lastName, salary);
// TODO Auto-generated constructor stub
}
public double calculateSalary(double raise) {
setSalary(getSalary() + getSalary()* raise/100 + bonus);
return getSalary();
}
public String ManagerDetails() {
return getFirstName().toString()+ getLastName().toString()+ Double.toString(getSalary()) ;
}
}
——————————————————————————————————————————
Driver.java
public class Driver {
public static void main (String [] args) {
Employee Bob_smith = new Employee(“Bob”, “Smith”, 45000) ;
Manager Sally_Jones = new Manager(“Sally”, “Jones”, 65000, 6500);
Bob_smith.setSalary(Bob_smith.calculateSalary(3));
Sally_Jones.setSalary(Sally_Jones.calculateSalary(5));
System.out.println(Bob_smith.employeedetails());
System.out.println(Sally_Jones.ManagerDetails());
}
}