need help with quetion below You are given the Measurable interface You work for
ID: 3533909 • Letter: N
Question
need help with quetion below
You are given the Measurable interface You work for a packaging company that makes boxes and cylindrical tubes for shipments. Your job is to write classes to be used in a larger software program. Write a box class that has one data field for the dimensions of the box (assume all boxes have a length that is the same as the width and height - prefect boxed) and a cylinder class that has two data fields, a height and a radius. Both classes must use the interfaces shown above. Measurable should be straight - forward but scaling an object in this context means multiplying the data fields by s - for example for s - factor of 2.0, a box length is doubled and for a cylinder both the radius and height are doubled. Area of a cylinder is 2pirdegree + 2pirh and volume of a cylinder is pir degree h. You need a reasonable constructor, reaconable get methods and a to String for each class. No mutators are required. Write both classes below. Write small.Explanation / Answer
class Box implements Measurable,Scalable
{
private double side;
public Box(double s)
{ side=s ; }
public double getSide()
{
return side;
}
public double area()
{
return (6*side*side);
}
public double volume()
{
return (side*side*side);
}
public String toString()
{ return "Box: Side: "+side+" Area :"+area()+" Volume :"+volume()";
}
}
class Cylinder implements Measurable,Scalable
{
private double radius;
private double height;
public Cylinder(double r,double h)
{ radius=r ;
height =h; }
public double getHeight()
{
return height;
}
public double getRadius()
{
return radius;
}
public double area()
{
return ((2*3.14*radius*radius) + (2*3.14*radius*height));
}
public double volume()
{
return (3.14*radius*radius*height);
}
public String toString()
{ return "Cylinder: Radius: "+radius+" Height: "+height+" Area :"+area()+" Volume :"+volume()";
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.