Here is a partially completed class and tester class for you to add to and test
ID: 3791392 • Letter: H
Question
Here is a partially completed class and tester class for you to add to and test the methods within a tester class. Open the Employee.java class. Read and add the appropriate code to complete the requirements. Compile the class. The Employee class can not be run.
public class EmployeeTester
{
public static void main (String [] args)
{
final double increase= 0.25;
// Create two instances of the Employee class
Employee jas = new Employee();
Employee abc = new Employee("Alice", "Cason", 4000);
//set first name, last name and salary for employee jas
jas.setFirst("James");
//add the additional information
//display the name and salary of both Employee objects
System.out.println("jas Employee first name: " + jas.getFirst());
//complete the code
//Determine the year to date salary for both employee
System.out.print(abc.getFirst() +" 's salary: ");
int mo = 9;
System.out.println(abc.getSalary());
System.out.println(abc.ytdSalary(mo));
//set and display salary with increase
abc.setSalary(abc.getSalary()+abc.getSalary()*increase);
System.out.println(abc.getSalary());
}//end method main
} //end class EmployeeTester
Explanation / Answer
/**
* Employee class that sets the first name, last name
* and salary of an employee.
* */
//Employee.java
public class Employee {
private String firstName;
private String lastName;
private double salary;
//default constructor
public Employee() {
this.firstName="";
this.lastName="";
this.salary=0;
}
//parameter constructor
public Employee(String firstName, String lastName, double salary)
{
this.firstName=firstName;
this.lastName=lastName;
this.salary=salary;
}
//Set first name of the employee
public void setFirst(String firstName) {
this.firstName=firstName;
}
//Get first name of the employee
public String getFirst() {
return firstName;
}
//Get salary of the employee
public double getSalary() {
return salary;
}
//Method to set salary of employee
public void setSalary(double salary) {
this.salary=salary;
}
}
---------------------------------------------------------------------------------------------
//EmployeeTester.java
public class EmployeeTester
{
public static void main (String [] args)
{
final double increase= 0.25;
// Create two instances of the Employee class
Employee jas = new Employee();
Employee abc = new Employee("Alice", "Cason", 4000);
//set first name, last name and salary for employee jas
jas.setFirst("James");
//add the additional information
jas.setSalary(5000);
//display the name and salary of both Employee objects
System.out.println("jas Employee first name: " + jas.getFirst());
//Determine the year to date salary for both employee
System.out.print(abc.getFirst() +" 's salary: ");
System.out.println("Salary of Alice");
System.out.println(abc.getSalary());
System.out.println("Salary of james");
System.out.println(jas.getSalary());
//set and display salary with increase
System.out.println("Increase alice salary by 25 %");
abc.setSalary(abc.getSalary()+abc.getSalary()*increase);
System.out.println("Alice current salary");
System.out.println(abc.getSalary());
}//end method main
} //end class EmployeeTester
---------------------------------------------------------------------------------------------
Sample output:
jas Employee first name: James
Alice 's salary: Salary of Alice
4000.0
Salary of james
5000.0
Increase alice salary by 25 %
Alice current salary
5000.0
Note :
System.out.println(abc.ytdSalary(mo)); cannot understand what this statement is.
Comment for what is that statement.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.