阅读以下说明和Java代码,将应填入(n)处的字句写在对应栏内。 [说明] 本程序的功能是给公司的员工Tom,Jack,Green增加薪水。三人的职位分别是programmer, Manager,CEO。 程序由6个类组成:WorkerTest

admin2009-02-15  45

问题 阅读以下说明和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 . getName ( ) +" \ tSalary:" + worker . 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);
}
}

选项

答案(1)salary (2)SalaryRalse (3)Worker (4) super. raise() (5)sala+=bonus及其等效形式

解析 (1)从Worker这个类的结构来看,它有两个属性ufinle和salary,因此这里应该填salary;
(2)~(3):很显然Programmer类和Manager类继承于 Worker类和SalaryRaise接口。
(4)~(5):CEO类继承于Manager类,而根据题意, CEO除了有Managor的涨幅,还有1000元的bonus。所以,CEO薪水的涨幅可以使用基类相同的方法super. raise(),然后再加上奖金sala+=bonus即可。
转载请注明原文地址:https://kaotiyun.com/show/TEjZ777K
0

最新回复(0)