2) Develop the following derived class Cylinder using base class Circle, must us
ID: 3558914 • Letter: 2
Question
2) Develop the following derived class Cylinder using base class Circle, must use base class methods when possible. Cylinder - height : double + setHeight (double ): void // Sets height to the given value + print():void // prints Cylinder info labeled and one per line + calculateTotalArea () : double // Calculates and returns total Area 2*PI*r * (h +r) + calculateLateralArea():double // Calculates and returns lateral area 2 *PI * r * h + getHeight() : double // Returns height + calculateVolume() : double // Calculate and return volume PI * r * r * h + equal(Cylinder): Boolean + Cylinder() + Cylinder ( double, double) 1) You are to design a base class that would represent a Circle. Given the following UML representation of a class write the Java code for the class: Circle # radius : double + setRadius (double ): void // Sets radius to the given value + Print():void // prints the circle info: radius, area and circumference labeled and one per line + calculateCircumference() : double // Calculates and returns circumference 2*PI*r + calculateArea():double // Calculates and returns area PI * r *r +getRadius() : double // Returns radius + toString(): String + equal(Circle): Boolean + Circle() + Circle (double) 3) Develop a Java test class to test the 2 classes (Circle and Cylinder) you developed for the previous questions. Read data for each instance of the class and use as many class methods as possible.Explanation / Answer
part 1) Methods of Class Circle are given below
public class Circle{
Private double R;
public void setRadius(double Radius)
{R=Radius;}
public void Print()
{
system.out.println("The Radius is %f ",R);
system.out.println("The Circumference is %f ",calculateCircumference());
system.out.println("The Area is %f ",calculateArea());
}
public double calculateCircumference()
{return(Math.PI*2*R);}
public double calculateArea()
{return(Math.PI*R*R);}
public double getRadius()
{return(R);}
public Boolean equal(Circle p)
{
if(p.calculateCircumference()==calculateCircumference())
{
return 1;
}
else
{
return 0;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.