网友您好, 请在下方输入框内输入要搜索的题目:
阅读以下说明和Java代码,将应填入(n)处的字句写在对应栏内。
[说明]
本程序的功能是给公司的员工Tom,Jack,Green增加薪水。三人的职位分别是programmer, Manager,CEO。
程序由6个类组成:WorkerTest是主类,programmer,Manager,CEO三个类,薪水增加的规则是 programmer的涨幅是5%;Manager的是10%;CEO也是Manager,但是它除了有Manager的涨幅,还有1000元的bonus。接口SalaryRaise提供了一个增加薪水的方法raise()。
[java程序]
public class WorkerTest {
public WorkerTest( ) {}
public static void main( String[] args) {
Programmer programmer = new Programmer( "Tom" ,3000);
Manager manager = new Manager( "Jack" ,4000);
CEO ceo = new CEO( "Green" ,4000);
Worker [] worker = new Worker[3];
programmer, raise( );
manager, raise( );
ceo. raise( );
worker[0] = programmer;
worker [1] = manager;
worker[2] = ceo;
for ( int i = 0 ;i < worker, length; i + + ) {
System. out. prinfln (" Name:" + worker [i]. getName ( ) +" \ tSalary:" + worker [i]. getSalary ());
public interface SalaryRaise { void raise( ); }
public class Worker {
public String name;
public double (1);
public Worker( ) {}
public String getName( ) {return name;}
public void setName( String name) {this. name = name;}
public double getSalary( ) {return salary;}
public void setSalary(double salary) { this. salary = salary; }
}
public class Programmer extends Worker implements (2) {
public Programmer( ) {}
public void raise( ) {
double pets=0.05;
double sala = this. getSalary( ) * (1 + pers);
this. setSalary (sala);
public Programmer( Siring name, double salary) t
this. name = name;
this. salary = salary;
public class Manager extends (3) implements SalaryRaise {
public Manager( ) { }
public Manager(String name, double salary) {
this. name = name;
this. salary = salary;
}
public void raise( ) {
double pets = 0.1;
double sala = this. getSalary() * (1 + pers);
this. setSalary(sala);
}
}
public class CEO extends Manager implements SalaryRaise {
public CEO() {}
public CEO( String name,double salary) {
this. name = name;
this. salary = salary;
}
public void raise( ) {
double bonus = 1000;
(4);
double sala = this. getSalary( );
(5);
this. setSalary(sala);
}
}
参考答案