您现在的位置是:Instagram刷粉絲, Ins買粉絲自助下單平台, Ins買贊網站可微信支付寶付款 >
01 訂閱 英文簡寫為3 jmu java m02(7-1 jmu-Java-03面向對象基礎-04-形狀-繼承(15 分))
Instagram刷粉絲, Ins買粉絲自助下單平台, Ins買贊網站可微信支付寶付款2024-06-24 00:01:16【】7人已围观
简介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);
&
很赞哦!(1524)
相关文章
- 03 湖北理工學院國際經濟與貿易專業(國際經濟與貿易專業開設院校有哪些)
- 01 #tiktok頭像圖片尺寸太小(zhidao.買粉絲.買粉絲)
- 03 漳州寶來汽車貿易有限公司(貸款購車協議合法嗎貸款購車協議)
- 01 #tiktok娛樂主播好賺錢嗎(百度知道怎么追問)
- 01 #tiktok安卓版詳細教程2023(百度知道「知道團隊」下線通知!)
- 01 #tiktok如何買粉(電腦版的百度首頁的買粉絲是什么?)
- 01 #tiktok安卓下載2023最新版(百度知道「知道團隊」下線通知!)
- 03 湖南先導國際貿易有限公司招聘(醫學生職業生涯規劃書)
- 01 #tiktok小店怎么上架產品(百度知道登陸)
- 03 溶血時網織紅細胞變化(溶血性輸血反應簡介)