2020.5.21

 
  
package ddss;
//4.2 SalariedEmployee : ColaEmployee 的子类,拿固定工资的员工。属性:月薪
public class SalariedEmployee extends ColaEmployee{
    double monSalary;//月薪
    
    public SalariedEmployee(String name,int month,double monSalary) {
        super(name,month);
        this.monSalary=monSalary;
    }
//    方法:getSalary(int month) 根据参数月份来确定工资,
//    如果该月员工过生日,则公司会额外奖励100 元。
    public double getSalary(int month) {
        if (super.month==month) {
            return monSalary +100;
        }else {
            return monSalary;
        }
        
    }
}
 
   
  
package ddss;
//4、 Cola公司的雇员分为以下若干类:(知识点:多态) [必做题]
//    4.1 ColaEmployee :这是所有员工总的父类,属性:员工的姓名,员工
//    的生日月份。方法:getSalary(int month) 根据参数月份来确定工资,
//    如果该月员工过生日,则公司会额外奖励100 元。
public class ColaEmployee {
    String name;
    int month;
    
    public ColaEmployee() {
    
    }
    
    public ColaEmployee(String name,int month){
        this.name=name;
        this.month=month;
    }
    
    public double getSalary(int month) {
        return 0;
    }
}
package fulei;

public class Rectangle extends Shape{
double Width;
double height;
public void getArea(){
    
}
public  void getPer(){
    
}
public Rectangle(double width, double height) {
    super();
    Width = width;
    this.height = height;
}

    
}




package fulei;

public class Circle extends Shape{
    double radius;
    public  void getPer(){
        
    }
    public void getArea(){
        
        

    }
}
 
  
 
1、设计四个类,分别是:(知识点:抽象类及抽象方法)
(1)Shape表示图形类,有面积属性area、周长属性per,颜色属性color,有两个构造方法(一个是默认的、一个是为颜色赋值的),还有3个抽象方法,分别是:getArea计算面积、getPer计算周长、showAll输出所有信息,还有一个求颜色的方法getColor。
(2)2个子类:
1)Rectangle表示矩形类,增加两个属性,Width表示长度、height表示宽度,重写getPer、getArea和showAll三个方法,另外又增加一个构造方法(一个是默认的、一个是为高度、宽度、颜色赋值的)。
2)Circle表示圆类,增加1个属性,radius表示半径,重写getPer、getArea和showAll三个方法,另外又增加两个构造方法(为半径、颜色赋值的)。
 (3)一个测试类PolyDemo,在main方法中,声明创建每个子类的对象,并调用2个子类的showAll方法。



package fulei;

public abstract class Shape {
double area;
double per;
String color;
double showAll;
public Shape() {
    super();
}
public Shape(String color) {
    super();
    this.color = color;
}
public abstract void getArea();
public abstract void getPer();
public String getColor() {
    return color;
}
public void setColor(String color) {
    this.color = color;
}

}

猜你喜欢

转载自www.cnblogs.com/yyyyym/p/12929793.html
今日推荐