NOTE The completed code must pass in the following compiler
NOTE: The completed code must pass in the following compiler. Please make absolutely sure it does before posting: http://codecheck.it/codecheck/files?repo=bj4fp&problem=ch03/c03_exp_3_6
And PLEASE post this as text and not as an image, and avoid making alterations to the original code such as removing/changing parameters, class and variable names etc.
~
Implement a class Employee. An employee has a name (a string) and a salary (a double). Provide a constructor with two parameters
public Employee(String employeeName, double currentSalary)
and methods
public String getName()
public double getSalary()
public void raiseSalary(double byPercent)
These methods return the name and salary, and raise the employee\'s salary by a certain percentage. Sample usage:
Employee harry = new Employee(\"Hacker, Harry\", 50000);
harry.raiseSalary(10); // Harry gets a 10% raise
Supply an EmployeeTester class that tests all methods.
Complete the following class in your solution:
Use the following class as your tester class:
Solution
//Employee.java
/**
An employee with a name and salary.
*/
public class Employee
{
private String name;
private double salary;
/**
Constructs an employee.
@param employeeName the employee name
@param currentSalary the employee salary
*/
public Employee(String employeeName, double currentSalary)
{
name=employeeName;
salary=currentSalary;
}
/**
Gets the employee name.
@return the name
*/
public String getName()
{
return name;
}
/**
Gets the employee salary.
@return salary
*/
public double getSalary()
{
return salary;
}
/**
Raises the salary by a given percentage.
@param percent the percentage of the raise
*/
public void raiseSalary(double percent)
{
salary= salary+salary*percent;
}
}//end of the Employee
---------------------------------------------------------------------------------
//EmployeeTester.java
/**
This program tests the Employee class.
*/
public class EmployeeTester
{
public static void main(String[] args)
{
//Create an instance of Employee with name and salary
Employee harry = new Employee(\"Harry Hacker\", 50000);
System.out.println(\"Name : \"+harry.getName());
System.out.println(\"Salary : \"+harry.getSalary());
//call raiseSalary with 10 percent
harry.raiseSalary(10);
//raise of 10 percent on 50000 becomes 5000 . This will be added to salary ,i.e 50000+5000=55000
//The expected value is 55000
System.out.println(\"Expected : 55000.0\");
}
}
-------------------------------------------------------------
Output:
Name : Harry Hacker
Salary : 50000.0
Expected : 55000.0

