public class Vehicle {
protected String brand;
protected String clr;
protected double speed;
public Vehicle(String brand, String clr, double speed) {
super();
this.brand = brand;
this.clr = clr;
this.speed = 0;
}
public Vehicle() {
super();
}
public String getClr() {
return clr;
}
public void setClr(String clr) {
this.clr = clr;
}
public double getSpeed() {
return speed;
}
public void setSpeed(double speed) {
this.speed = speed;
}
public String getBrand() {
return brand;
}
public void run(){
System.out.println(brand+"牌的"+clr+"色的汽车正以"+speed+"速度行驶");
}
}
public class Car extends Vehicle {
int lader;
public int getlader(){
return lader;
}
public Car(String brand, String clr, double speed, int lader) {
super(brand, clr, speed);
this.lader = lader;
}
public int getLader() {
return lader;
}
public void setLader(int lader) {
this.lader = lader;
}
public void run(){
System.out.println(brand+"牌的"+clr+"色的汽车正以"+speed+"速度行驶"+"载人数为"+lader);
}
}
public class text {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Vehicle v=new Vehicle("benz","black",200);
v.setSpeed(200);
v.run();
Car c=new Car("Handa","red",200,5);
c.setSpeed(200);
c.run();
}
}
public abstract class Shape {
protected double area;
protected double per;
protected String color;
public Shape(String color) {
super();
this.color = color;
}
public Shape() {
super();
}
public abstract void getArea();
public abstract void getPer();
public abstract void showAll();
}
public class Rectangle extends Shape{
private double width;
private double height;
public Rectangle(String color, double width, double height) {
super(color);
this.width = width;
this.height = height;
}
public void getArea() {
area = width * height;
}
public void getPer() {
per = (width + height) * 2;
}
public void showAll() {
System.out.println("矩形的周长为:" + per + " 矩形的面积为:" + area);
}
}
public class Circle extends Shape{
private double radius;
public Circle(String color, double radius) {
super(color);
this.radius = radius;
}
public void getArea() {
area = 3.14 * radius * radius;
}
public void getPer() {
per = 2 * 3.14 * radius;
}
public void showAll() {
System.out.println("圆的周长为:" + per + " 圆的面积为:" + area);
}
}
public class text {
public static void main(String[] args) {
Rectangle r = new Rectangle("蓝", 3.0, 6.0);
Circle c = new Circle("红", 2.0);
r.getArea();
r.getPer();
c.getArea();
c.getPer();
r.showAll();
c.showAll();
}
}