第十一周上机作业

package test;

public class mians {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
        Car r=new Car("大众","红色",20);
        r.setBrand("宝马");
        r.run();
        Vehicle s=new Vehicle();
        s.brand="Honda";
        s.coulor="red";
        s.speed=30;
        s.run();
        s.loader=2;
	}

}

  

package test;

public class Car {
	String brand;
	String coulor;
	double speed;
	public Car(String brand, String coulor, double speed) {
		super();
		this.brand = brand;
		this.coulor = coulor;
		this.speed = speed;
	}
	public String getBrand() {
		return brand;
	}
	public void setBrand(String brand) {
		this.brand = brand;
	}
	public String getCoulor() {
		return coulor;
	}
	public void setCoulor(String coulor) {
		this.coulor = coulor;
	}
	public double getSpeed() {
		return speed;
	}
	public void setSpeed(double speed) {
		this.speed = speed;
	}
	public void run(){
		System.out.println(coulor+brand+"开到了"+speed);
	}


}

  

package test;

public class Vehicle extends happy{
	int loader;
	
	
}

  

package test;

public class happy {
	String brand;
	String coulor;
	double speed;
	public void run(){
		System.out.println(coulor+brand+"速度为"+speed);
	}
	
	


}

  

 

 

2.

 package hhhhkj;
 2 
 3 public abstract class Shape {
 4     protected double area;
 5     protected double per;
 6     protected String color;
 7 
 8     public Shape() {
 9     }
10 
11     public Shape(String color) {
12         this.color = color;
13     }
14 
15     public t void getArea();
16 
17     public  void getPer();
18 
19     public  void showAll();
20 
21 }

  

 package hhhhkj;
 2 
 3 public class Rectangle extends Shape {
 4     double width;
 5     double height;
 6 
 7     public Rectangle() {
 8     }
 9 
10     public Rectangle(double width, double height, String color) {
11         super();
12         this.width = width;
13         this.height = height;
14         this.color = color;
15     }
16 
17     public void getArea() {
18         area = width * height;
19     }
20 
21     public void getPer() {
22         per = (width + height) * 2;
23     }
24 
25     public void showAll() {
26         System.out.println("矩形的面积为:" + area + ",矩阵的周长为:" + per + ",颜色为:" + color);
27     
28 }

 

  

package hhhhkj;
 2 
 3 public class ceshilei {
 4 
 5     public static void main(String[] args) {
 6         // TODO Auto-generated method stub
 7         Shape a = new Circle(4, "紫色");
 8         Shape b = new Rectangle(1, 6, "红色");
 9         a.getArea();
10         a.getPer();
11         
12         b.getArea();
13         b.getPer();
14         
15     }
16 
17 }

  

 

posted @ 2020-05-14 12:02  来咬我啊20675  阅读(116)  评论(0)    收藏  举报