Implement a class Employee. An employee has a name (a string) and a salary (a do
ID: 3630171 • Letter: I
Question
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.
Explanation / Answer
please rate - thanks
import java.util.*;
class employeeTest
{public static void main(String args[])
{employee harry = new employee("Hacker, Harry", 50000);
employee john = new employee("Jones, John", 100000);
System.out.println("Before raise");
print(harry);
print(john);
harry.raiseSalary(10); // Harry gets a 10% raise
john.raiseSalary(5); // John gets a 5% raise
System.out.println("After raise");
print(harry);
print(john);
}
public static void print(employee e)
{
System.out.println("Employee:"+e.getName()+" "+"-Salary:"+e.getSalary());
}
}
-----------------------------
class employee
{
private String name;
private double salary;
public employee(String n, double s)
{ name=n;
salary=s;
}
public void setName(String n)
{
name=n;
}
public void setSalary(double s)
{ salary=s;
}
public String getName()
{
return name;
}
public double getSalary()
{
return salary;
}
public void raiseSalary(double p)
{salary=salary+(salary*p/100.);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.