您现在的位置是:Instagram刷粉絲, Ins買粉絲自助下單平台, Ins買贊網站可微信支付寶付款 > 

01 訂閱 英文簡寫為3 jmu java m02(7-1 jmu-Java-03面向對象基礎-04-形狀-繼承(15 分))

Instagram刷粉絲, Ins買粉絲自助下單平台, Ins買贊網站可微信支付寶付款2024-06-06 04:24:36【】0人已围观

简介7-1jmu-Java-03面向對象基礎-04-形狀-繼承(15分)自己寫的,也才學不容易還望采納importjava.util.*;abstractclassShape{  &n

7-1 jmu-Java-03面向對象基礎-04-形狀-繼承(15 分)

自己寫的,也才學不容易還望采納

import java.util.*;

abstract class Shape{

    final static double PI=3.14;

    public abstract double getPerimeter();

    public abstract double getArea();

    

    public static double sumAllArea(Shape []shapes) {

        double x=0;

        for(Shape e:shapes) {

            x+=e.getArea();

        }

        return x;

    }

    public static double sumAllPerimeter(Shape []shapes) {

        double y=0;

        for(Shape e:shapes) {

            y+=e.getPerimeter();

        }

        return y;

    }

}

class Rectangle extends Shape{

    private int width;

    private int length;

    

    public double getPerimeter() {

        return 2*(width+length);

    }

    

    public double getArea() {

        return width*length;

    }

    public Rectangle(int width,int length) {

        this.width=width;

        this.length=length;

    }

    @Override

    public String toString() {

        return "Rectangle [width=" + width + ", length=" + length + "]";

    }

    

}

class Circle extends Shape{

    private int radius;

    

    public double getPerimeter() {

        // TODO Auto-generated method stub

        return 2*PI*radius;

    }

    public double getArea() {

        // TODO Auto-generated method stub

        return PI*radius*radius;

    }

    

    public Circle(int radius) {

        this.radius=radius;

    }

    @Override

    public String toString() {

        return "Circle [radius=" + radius + "]";

    }

    

}

public class Main{

    public static void main(String[] args) {

        Scanner in=new Scanner(System.in);

        int n;

        n=in.nextInt();

        Shape shapes[]=new Shape[n];

        for(int i=0;i<n;i++) {

            String s=in.next();

            switch(s) {

            case "rect":

                int width,length;

                width=in.nextInt();

                length=in.nextInt();

                shapes[i]=new Rectangle(width, length);

     &

很赞哦!(89442)

Instagram刷粉絲, Ins買粉絲自助下單平台, Ins買贊網站可微信支付寶付款的名片

职业:程序员,设计师

现居:新疆和田洛浦县

工作室:小组

Email:[email protected]