Java第十四周作业

Posted 曹新

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java第十四周作业相关的知识,希望对你有一定的参考价值。

package oop;

public class Vehicle {
    private String brand;
    private String color;
    private double speed;
    
    public Vehicle(String brand,String color,double speed){
        this.brand = brand;
        this.color = color;
        this.speed = 0;
    }
    
    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 oop;

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

    public int getLoader() {
        return loader;
    }

    public void setLoader(int loader) {
        this.loader = loader;
    }
    
    public void run(){
        System.out.println(super.getBrand()+"牌的"+super.getColor()+"色的汽车正以"+super.getSpeed()+"速度行驶"+"载人数为"+loader);
    }
}
package oop;

public class Test {
    public static void main(String args[]){
        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();
    }

}

 package oop;

public abstract class Shape {
    double area;
    double per;
    String clr;
    
    public Shape(){
        
    }
    
    public Shape(String clr){
        this.clr = clr;
    }
    
    public abstract double getPer();
    public abstract double getArea();
    public abstract void showAll();
    public String getClr(){
        return clr;
    }

}
package oop;

public class Rectangle extends Shape{
    double width;
    double height;
    
    public double getPer() {
            return (width + height) * 2;
        }

        public double getArea() {
            return width * height;
        }
    public Rectangle(){
        super();
    }
    public Rectangle(double width,double height,String clr){
        super();
        this.width = width;
        this.height = height;
        this.clr = clr;
    }
    
    public void shwAll(){
         System.out.println("长是"+width+"宽是"+height+"颜色是"+clr+"周长是"+getPer()+"面积是"+getArea());
    }

    @Override
    public void showAll() {
        // TODO Auto-generated method stub
        
    }

}
package oop;

public class Circle extends Shape {
       public double getPer() {
           return 2*3.14*radius;
       }
       public double getArea() {
           return 3.14*radius*radius;
       }
       double radius;
   public void showAll(){
       System.out.println("半径是"+radius+"颜色是"+clr+"周长是"+getPer()+"面积是"+getArea());
   }
   
   public Circle(double radius,String clr) {
       super();
       this.radius = radius;
       this.clr = clr;
   }
   public Circle() {
       super();
   }
   
           
      
      

}
package oop;

public class Testa {
     public static void main(String[] args) {
         //TODO Auto-generated method stub
        Rectangle r=new Rectangle(10,10,"蓝");
        r.showAll();
        Circle c=new Circle(10,"橙");
        c.showAll();
     }
}

以上是关于Java第十四周作业的主要内容,如果未能解决你的问题,请参考以下文章

Java第十四周作业

第十四周Java作业

JAVA第十四周作业

Java第十四周作业

Java第十四周作业

第十四周进度条