2018/12/11

2018/12/11

1.在这里插入图片描述

public class Building {
	private	int length;
	private	int width;
	private int level;
	private static	int unitprice = 4000;
	private static  int leveladd = 100;
	public Building(int length, int width, int level) {
		this.length = length;
		this.width = width;
		this.level = level;
	}
	void message(){
		System.out.println("长:"+length+"宽:"+width+
				"层数:"+level+"单价:"+(unitprice+(level-1)*leveladd)+"加价:"+
				(level-1)*leveladd);
		int sum = 0;
		for(int i =0;i<level;i++){
			sum += (unitprice+i*leveladd)*length*width;
		}
		System.out.println("总面积:"+level*width*length+"总房价:"+sum);
	}
}

Building b = new Building(10,10,10);
		b.message();

2.在这里插入图片描述

public class Box {
	private	int length=1;
	private	int width=1;
	private	int high=1;
	public Box(int length, int width, int high) {
		this.length = length;
		this.width = width;
		this.high = high;
	}
	void message(){
		System.out.println("长:"+length+"宽:"+width+"高:"+
				high+"面积:"+length*width*high);
	}
	
}
Box b = new Box(15,20,10);
		b.message()

在这里插入图片描述
在这里插入图片描述

public class Pool {
	double radius;
	double width;
	double unitprice1;
	double unitprice2;
	public Pool(double radius, double width, double unitprice1, double unitprice2) {
		this.radius = radius;
		this.width = width;
		this.unitprice1 = unitprice1;
		this.unitprice2 = unitprice2;
	}
	void message (){
		double pi = 3.14;
		double a = radius*radius*pi*unitprice1;
		double b = (pi*(width+radius)*(width+radius)-pi*radius*radius)*unitprice2;
		System.out.println("中心岛半径是:"+radius+"游泳池半径是:"+width+
				"中心岛单价是:"+a+"游泳池单价是:"+b);
	}
	
}

Pool p = new Pool(10,10,100,100);
		p.message();

猜你喜欢

转载自blog.csdn.net/weixin_43986054/article/details/84960978