public static void main(String[] args) {
double w;
double h;
double d;
Scanner input = new Scanner(System.in);
System.out.print ("Enter the width of your box:");
w= input.nextDouble();
System.out.print ("Enter the height of your box:");
h= input.nextDouble();
System.out.print ("Enter the depth of your box:");
d= input.nextDouble();
Box boxOne = new Box(w, h, d);
System.out.println(boxOne.toString());
boxOne.setDim(w, h, d);
}
}
class Box
{
private double width = 1.0;
private double height = 1.0;
private double depth = 1.0;
public Box (double w, double h, double d)
{
setWidth(w);
setHeight(h);
setDepth(d);
}
public void setWidth(double w)
{
if(w > 0)
{
width = w;
}
else
{
width = 1.0;
}
}
public void setHeight(double h)
{
if(h > 0)
{
height = h;
}
else
{
height = 1.0;
}
}
public void setDepth(double d)
{
if(d > 0)
{
depth = d;
}
else
{
depth = 1.0;
}
}
public void setDim(double width, double height, double depth)
{
double volume=width*height*depth;
System.out.println("The volume of the box is "+volume);
}
public double volume ()
{
}
public String getWidth()
{
return String.format("%f",width);
}
public String getHeight()
{
return String.format("%f",height);
}
public String getDepth()
{
return String.format("%f",depth);
}
public String toString()
{
return String.format("Width is %s.\nHeight is %s.\nDepth is %s.", getWidth(), getHeight(),getDepth());
}
public boolean equalTo (Box o)
{
}
}
Я не понимаю, как использовать методы public boolean equalTo (Box o)
и public double volume()
в этом коде. И что я должен написать в телах этих двух методов? И как их использовать в основном методе? Я не понимаю эти два метода. как создать метод boolean equalTo()
и метод double volume()
и как их проверить?