我是新手java,我想知道如何Boxvolume从我的volume方法中打印变量。
我明白我需要创建Boxvolume一个全局变量。因此,如果有人可以帮助我,我将不胜感激。
这是我的代码:
public static void main(String[] args) {
Box a = new Box(20, 30, 40);
ArrayList<Box> boxes = new ArrayList<>();
boxes.add(a);
for (Box bx : boxes) {
bx.print();
}
double V = volume(Boxvolume);
System.out.println(V);
}
class Box {
int width;
int height;
int depth;
public Box(int w, int h, int d) {
this.width = w;
this.height = h;
this.depth = d;
}
public double volume(double BoxV) {
int Boxvolume = width * height * depth;
return Boxvolume;
}
public double price(double BV) {
double Boxprice = volume(BV) * 5;
return Boxprice;
}
public void print() {
System.out.println(this.width);
System.out.println(this.height);
System.out.println(this.depth);
System.out.println();
}
}
叮当猫咪
SMILET
相关分类