2018/12/11
public class Building {
private int length;
private int width;
private int level;
private static int unitprice = 4000 ;
private static int leveladd = 100 ;
public int getLength ( ) {
return length;
}
public void setLength ( int length) {
this . length = length;
}
public int getWidth ( ) {
return width;
}
public void setWidth ( int width) {
this . width = width;
}
public int getLevel ( ) {
return level;
}
public void setLevel ( int level) {
this . level = level;
}
public static int getUnitprice ( ) {
return unitprice;
}
public static void setUnitprice ( int unitprice) {
Building. unitprice = unitprice;
}
public static int getLeveladd ( ) {
return leveladd;
}
public static void setLeveladd ( int leveladd) {
Building. leveladd = leveladd;
}
public Building ( int length, int width, int level) {
this . length = length;
this . width = width;
this . level = level;
}
public void show ( ) {
int sum = length* width* level;
int s = length* width;
int p = 0 ;
for ( int a = 0 ; a< level; a++ ) {
p += s* ( unitprice+ a* leveladd) ;
}
System. out. println ( "长度为: " + length) ;
System. out. println ( "宽度为: " + width) ;
System. out. println ( "层数为: " + level) ;
System. out. println ( "单价为: " + unitprice) ;
System. out. println ( "加价为: " + leveladd) ;
System. out. println ( "总面积为: " + sum) ;
System. out. println ( "总价格为: " + p) ;
}
}
Building a = new Building ( 10 , 15 , 20 ) ;
a. show ( ) ;