14周Java作业

package bao;

public class text {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        Rectangle R = new Rectangle(5,10,"蓝");
        R.showAll(5, 10);
        System.out.println();
        Circle C = new Circle(6,"红");
        C.showAll(6, "红");
    }

}
class Shape{
    int area;
    int per;
    String color;
    public Shape() {
        super();
    }
    public Shape(String color) {
        super();
        this.color = color;
    }
    void getArea(){
        System.out.println("该图形的面积为:"+area);
    }
    void getPer(){
        System.out.println("该图形的面积为:"+per);
    }
    void showAll(){
        System.out.println("该图形的面积为:"+area);
        System.out.println("该图形的面积为:"+per);
        
        System.out.println("该图形的颜色为:"+color);
    }
    void getColor(){
        System.out.println("该图形的颜色为:"+color);
    }
}
class Rectangle extends Shape{
    int width;
    int height;
    public Rectangle() {
        super();
    }
    public Rectangle(int width, int height,String color) {
        super();
        this.width = width;
        this.height = height;
        this.color = color;
    }
    void getArea(){
        int Area = width*height;
        System.out.println("该图形的面积为:"+Area);
    }
    void getPer(){
        int Per = 2*(width+height);
        System.out.println("该图形的面积为:"+Per);
    }
    void showAll(int length,int width){
        System.out.println("该图形的长为:"+length);
        System.out.println("该图形的宽为:"+width);
        int Area = length*width; 
        System.out.println("该图形的面积为:"+Area);
        int Per = 2*(length+width); 
        System.out.println("该图形的面积为:"+Per);
        System.out.println("该图形的颜色为:"+color);
    }
}
class Circle extends Shape{
    int radius;

    public Circle() {
        super();
    }

    public Circle(int radius,String color) {
        super();
        this.radius = radius;
        this.color = color;
    }
    void getArea(){
        double Area = radius*radius*3.14;
        System.out.println("该图形的面积为:"+Area);
    }
    void getPer(){
    double Per = 2*3.14*radius;
    System.out.println("该图形的周长为:"+Per);
    }
    void showAll(int radius,String color){
System.out.println("该图形的半径为:"+radius); double Area = radius*radius*3.14; System.out.println("该图形的面积为:"+Area); double Per = 2*3.14*radius; System.out.println("该图形的周长为:"+Per); System.out.println("该图形的颜色为:"+color); } }

 

 

package bao;

public class text2 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        Vehicle v = new Vehicle("landian","炫蓝色",0);
        v.run(180);
        Car c = new Car(2);
        c.run(120, 2, "V5", "魔力红");
    }

}
class Vehicle{
    private String brand;
    private String color;
    private double speed;
    public Vehicle() {
        super();
    }
    public Vehicle(String brand, String color, double speed) {
        super();
        this.brand = brand;
        this.color = color;
        this.speed = speed;
    }
    public String getColorl() {
        return color;
    }
    public void setColorl(String color) {
        this.color = color;
    }
    public double getSpeed() {
        return speed;
    }
    public void setSpeed(double speed) {
        this.speed = speed;
    }
    void run(double speed){
        System.out.println("一辆"+color+"的颜色"+brand+"的车以"+speed+"的速度行驶");
    }
    
}
class Car extends Vehicle{
    int loader;

    public Car() {
        super();
    }

    public Car(int loader) {
        super();
this.loader = loader; }
void run(double speed,int loader,String brand, String color){ System.out.println("一辆"+color+"的颜色"+brand+"载人数为"+loader+"的车以"+speed+"的速度行驶"); } }

 

posted @ 2021-06-18 17:20  宿命ゆ偏執  阅读(20)  评论(0编辑  收藏  举报