第十二周上机

1.

package hhhhkj;

public class Shape {
	double area;
	double per;
	String coulor;
	public Shape(int area, int per, String coulor) {
		super();
		this.area = area;
		this.per = per;
		this.coulor = coulor;
	}
	public String getCoulor() {
		return coulor;
	}
	public void setCoulor(String coulor) {
		this.coulor = coulor;
	}
	public Shape(){
		super();
	}
	public double getArea() {
		return area;
	}
	public void setArea(int area) {
		this.area = area;
	}
	public double getPer() {
		return per;
	}
	public void setPer(int per) {
		this.per = per;
	}
	public void showall(){
		Shape r=new Shape();
		r.getArea();
		r.getCoulor();
		r.getPer();
		System.out.println("颜色为"+coulor);
		System.out.println("周长为"+per);
		System.out.println("面积为"+area);
	}
	
	

}

  

package hhhhkj;

public class Rectangle  extends Shape{
	int width;
	double heigth;
	public void getarea(){
		area=width*heigth;
		System.out.println("面积为"+area);
		
	}
	public void getpers(){
		per=2*(width+heigth);
		System.out.println("周长为"+per);
		
	}
	public void showall1(){
		
		System.out.println("颜色为"+coulor);
		System.out.println("周长为"+per);
		System.out.println("面积为"+area);
		
	}
}

  

package hhhhkj;

public class Circle extends Shape{
	int ridus=3;
	double pero;
	double areao;
	public void getper()
	{
		pero=2*3.14*ridus;
		System.out.println("周长为"+pero);
	}
	public void getarea(){
		areao=3.14*ridus*ridus;
		System.out.println("面积为"+areao);
		
			
		}
	public void showall(){
		
		System.out.println("周长为"+pero);
		System.out.println("面积为"+areao);
	}
}
	
	

  测试类

package hhhhkj;

public class main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Shape s=new Shape();
		s.per=3.4;
		s.area=4.5;
		
		s.coulor="红色";
		s.showall();
		
		Rectangle t=new Rectangle();
		t.width=2;
		t.heigth=3.4;
		t.getarea();
	t.getpers();
		t.showall1();
		Circle o=new Circle();
		o.getarea();
		o.ridus=2;
		o.showall();
		
		
	}

}

  2.

package work;

public class ColaEmployee {
    String name;
    int month;

    public ColaEmployee() {

    }

    public ColaEmployee(String name, int month) {
        super();
        this.name = name;
        this.month = month;
    }

    public double getSalary(int month) {
        return 0;
    }

}

  

package work;

public class SalariedEmployee extends ColaEmployee {
    double monSalary;

    public SalariedEmployee() {
        super();
        // TODO Auto-generated constructor stub
    }

    public SalariedEmployee(String name, int month, double monSalary) {
        super(name, month);
        this.monSalary = monSalary;
    }

    public double getSalary(int month) {
        if (super.month == month) {
            return monSalary + 100;
        } else {
            return monSalary;
        }
    }

}

  

package work;

public class HourlyEmployee extends ColaEmployee {
    private int hourSalary;
    private int hourNum;

    public HourlyEmployee(String name, int month, int hourSalary, int hourNum) {
        super(name, month);
        this.hourSalary = hourSalary;
        this.hourNum = hourNum;

    }

    public double getSalary(int month) {
        if (super.month == month) {
            if (hourNum > 160) {
                return hourSalary * 160 + hourSalary * (hourNum - 160) * 1.5 + 100;
            } else {
                return hourSalary * hourNum + 100;
            }
        } else {
            if (hourNum > 160) {
                return hourSalary * 160 + hourSalary * (hourNum - 160) * 1.5;
            } else {
                return hourSalary * hourNum;
            }
        }

    }

}

  

package work;

public class SalesEmployee extends ColaEmployee {
    private int monthSales;
    private double royaltyRate;

    public SalesEmployee(String name, int month, int monthSales, double royaltyRate) {
        super(name, month);
        this.monthSales = monthSales;
        this.royaltyRate = royaltyRate;
    }

    public double getSalary(int month) {
        if (super.month == month) {
            return monthSales * royaltyRate + 100;
        } else {
            return monthSales * royaltyRate;
        }
    }

}

  

package paksjdaa;

public class Company {
    public void getSalary(ColaEmployee c, int month) {
        System.out.println(c.name + "在" + month + "月的月薪为" + c.getSalary(month) + "元");
    }

}

  3.

package wok;

public interface Fruit {

}

package wok;

public class Apple extends Fruit {
    public Apple() {
        System.out.println("创建了一个苹果类对象");
    }
}

package wok;

public class Banana extends Fruit {
    public Banana() {
        System.out.println("创建了一个香蕉类对象");
    }
}

package wok;

public class Grape extends Fruit {
    public Grape() {
        System.out.println("创建了一个葡萄类对象");
    }
}

  


posted @ 2020-05-21 11:46  来咬我啊20675  阅读(90)  评论(0)    收藏  举报