请教一段java编程

来源:百度知道 编辑:UC知道 时间:2024/07/04 13:11:22
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.

public class EmployeeTester
{
public static void main(String []args){
Employee harry = new Employee("Hacker, Harry", 50000);
System.out.println(harry.getName()+"'s salary is"+harry.getSalary());
harry.raiseSalary(10);
System.out.println(harry.getName()+"'s salary is"+harry.getSalary());
}
}

class Employee
{
private String name;
private double salary;

public Employee(String employeeName,double currentSalary){
name = employeeName;
salary = currentSalary;
}
public String getName(){
return name;
}
public double getSalary(){
return salary;
}
public void raiseSalary(double byPercent){
salary+=(salary*byPercent/100);
}
}