第十四周作业

package com.gd.df;

public class vehicle {
private String brand;
private String color;
private double speed;
public vehicle(String brand, String color, double speed) {
super();
this.brand = brand;
this.color = color;
this.speed = speed;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public double getSpeed() {
return speed;
}
public void setSpeed(double speed) {
this.speed = speed;
}
public void run(){
System.out.println(brand+"牌的"+color+"车正在以"+speed+"速度奔跑");
}


}

 

 

package com.gd.df;

public class Car extends vehicle{
private int loader;
public int getLoader() {
return loader;
}

public void setLoader(int loader) {
this.loader = loader;
}

public Car(String brand, String color, double speed, int loader) {
super(brand, color, speed);
this.loader = loader;
}

public void run() {
System.out.println("品牌是" + super.getBrand() + ",颜色是" + super.getColor() + ",载人数为"
+ loader + "的汽车,正在以" + super.getSpeed() + "速度奔跑");
}

}

 

 

 

package com.gd.df;

public class Text {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
vehicle v = new vehicle("benz", "black", 100);
v.setSpeed(100);
v.run();
Car c = new Car("Honda", "red", 100, 2);
c.setSpeed(200);
c.run();

}

}

 

 

 

 

 

package com.gd.dd;

public class Shape {
private double area;
private double per;
private String color;


public Shape() {
}


public Shape(String color) {
this.color=color;
}

public Shape(double area, double per, String color) {
super();
this.area = area;
this.per = per;
this.color = color;
}

public double getArea() {
return area;
}
public void setArea(double area) {
this.area = area;
}
public double getPer() {
return per;
}
public void setPer(double per) {
this.per = per;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}

public void showAll() {

}
public void fetColor() {

}
public void getcolor() {
System.out.println("该图形颜色是"+color);
}

}

 

 

 

package com.gd.dd;

public class Rectangle extends Shape {
private double Width;
private double height;



public Rectangle() {
super();
}

public Rectangle(double width, double height,String color) {
super( color);
Width = width;
this.height = height;
}
public Rectangle(String color) {
super(color);
}

public double getWidth() {
return Width;
}

public void setWidth(double width) {
Width = width;
}

public double getHeight() {
return height;
}

public void setHeight(double height) {
this.height = height;
}
public double getArea() {
return Width*height;
}
public double getPer() {
return (Width+height)*2;
}
public void showAll() {
System.out.println("该矩形的面积是"+getArea()+"周长是"+getPer());
}

}

 

 

package com.gd.dd;

public class Circle extends Shape{
private double radius;
public Circle() {
super();
}

public Circle(double radius, String color) {
super(color);
this.radius = radius;

}

public double getRadius() {
return radius;
}

public void setRadius(double radius) {
this.radius = radius;
}

public double getArea() {
return radius*radius*3.14;
}
public double getPer() {
return 2*3.14*radius;
}
public void showAll() {
System.out.println("这个圆的面积是"+getArea()+",周长是"+getPer());
}

}

 

 

package com.gd.dd;

public class Text {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Rectangle a=new Rectangle(4.6,6.1,"pick");
a.showAll();
a.getcolor();
Circle b=new Circle(5.6,"rad");
b.showAll();
b.getcolor();

}

}

 

 

 

 

posted @ 2021-06-10 20:03  高杨翔  阅读(31)  评论(0编辑  收藏  举报