📄 boxtest.java
字号:
//BoxTest.java
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
class Box{
private double length;
private double width;
private double high;
public Box(){
length=1;
width=1;
high=1;
}
public Box(double a,double b,double c){
if(a<=0||b<=0||c<=0){
System.out.println("invalid input");
System.exit(0);
}
else{
length=a;
width=b;
high=c;
}
}
public double getVolume(){
return(length*width*high);
}
public double getLength(){
return length;
}
public double getWidth(){
return width;
}
public double getHigh(){
return high;
}
}
public class BoxTest{
public static void main(String args[]){
Box box=new Box(1.5,2.4,3);
DecimalFormat twoDigits=new DecimalFormat("0.00");
String output="The length of box is:"+twoDigits.format(box.getLength())
+"\nThe width of box is:"+twoDigits.format(box.getWidth())
+"\nThe high of box is:"+twoDigits.format(box.getHigh())
+"\nThe volume of box is:"+twoDigits.format(box.getVolume());
JOptionPane.showMessageDialog(null,output,"Box Test",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -