定义一个圆形盒子类GircleBox,有私有的半径1、高h、体积v三个实型数据成员;定义一个带两个参数的set方法,用于给和h赋值,并计算盒子的体积;定义一个成员方法show(),它能以(r.h,v)“格式输出盒子数据;在main()方法中定义一个CirdeBox对象,进行初始化,并输出该盒子的信息
【输入形式】 r h 空格隔开
【输出形式】(r,h,v)输出数据取小数点后2位
可以参考一下,如有帮助,请采纳!
import java.util.Scanner;
public class Box{
int length ;
int width ;
int height ;
public void setBox(int l,int w,int h){
length = l;
width = w;
height = h;
}
public int volume(){
return length * width * height;
}
public static void main(String[] args) {
Box b = new Box();
Scanner input = new Scanner(System.in);
System.out.print("长:");
int l = input.nextInt();
System.out.print("宽:");
int w = input.nextInt();
System.out.print("高:");
int h =input.nextInt();
b.setBox(l, w, h);
System.out.println("体积为:" + b.volume());
}
}