「java盒子制作」盒子的制作
本篇文章给大家谈谈java盒子制作,以及盒子的制作对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、用java编写,求大神解答,跪谢了! 假设需要制造一个带有四个按钮和两个灯泡的盒子并具有以下功能:
- 2、编写一个盒子类Box的Java程序。 将参数传递给构造方法,计算盒子体积 capacity,在控制台输出。
- 3、用JAVA编写:设计并实现类Box,所包含的实例数据表示盒子的高度、宽度和厚度,一个boolean型实例数据
用java编写,求大神解答,跪谢了! 假设需要制造一个带有四个按钮和两个灯泡的盒子并具有以下功能:
这12个步骤已经详细的列出了做题的思想。 你就跟着思想一步一步来。代码是从上倒下一步一步执行的。 关键字 if 判断
编写一个盒子类Box的Java程序。 将参数传递给构造方法,计算盒子体积 capacity,在控制台输出。
class Box{
private double length;
private double width;
private double height;
public Box() {
if(lenght 0 || width 0 || height 0) {
System.out.println("输入值不合法!");
}
System.out.println("盒子体积是:"+length*height*width);
}
}
用JAVA编写:设计并实现类Box,所包含的实例数据表示盒子的高度、宽度和厚度,一个boolean型实例数据
public class Box {
private double height, width, thickness;
private boolean full;
Box(double height, double width, double thickness){
this.height=height;
this.width=width;
this.thickness=thickness;
full=false;
}
public double getHeight(){
return height;
}
public double getWidth(){
return width;
}
public double thickness(){
return thickness;
}
public boolean getFull(){
return full;
}
public void setHeight(double height){
this.height=height;
}
public void setWidth(double width){
this.width=width;
}
public void setThickness(double thickness){
this.thickness=thickness;
}
public void setFull(boolean full){
this.full=full;
}
public String toString(){
String s="";
if(getFull()==true)
s="The height of the box is "+getHeight()+";"
+"The height of the box is "+getHeight()+";"
+"The height of the box is "+getHeight()+";"
+"and the box is full";
else
s="The height of the box is "+getHeight()+";"
+"The height of the box is "+getHeight()+";"
+"The height of the box is "+getHeight()+";"
+"and the box is not full";
return s;
}
public static void main(String args[]){
Box b1=new Box(12.1,10.3,9.5);
Box b2=new Box(5.3,3.5,2.5);
System.out.println(b1);
System.out.println(b2);
b1.setFull(true);
b1.setHeight(15);
b1.setWidth(13);
b1.setThickness(14);
b2.setHeight(6);
b2.setWidth(4);
b2.setThickness(8);
System.out.println(b1);
System.out.println(b2);
}
}
java盒子制作的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于盒子的制作、java盒子制作的信息别忘了在本站进行查找喔。