面积之和java代码

面积之和java代码,第1张

Geometry.java

public abstract class Geometry { 
	public abstract double getArea();
	}

TotalArea.java

public class TotalArea {
	Geometry[] tuxing;
	double totalArea=0; 
	public void setTuxing(Geometry[] t) {
		tuxing=t;
		}
	public double computerTotalArea() {
		for(int i=0;i

Rect.java

public  class Rect extends Geometry {
	double a,b; 
	Rect(double a,double b) { 
		this.a = a; 
		this.b = b; 
		}
public double getArea(){
	return a*b;
}
}

Circle.java

public class Circle extends Geometry {
	double r; 
	Circle(double r) {
		this.r = r; 
		}
	public double getArea(){
		return 3.14*r*r;
	}
}

MainClass.java

public class MainClass{ 
	public static void main(String args[]) {
		Geometry [] tuxing=new Geometry[29]; 
		for(int i=0;i

运行结果:

 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/801325.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-07
下一篇 2022-05-07

发表评论

登录后才能评论

评论列表(0条)