Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using object-oriented programming approach, write a Java program that computes a

ID: 3761891 • Letter: U

Question

Using object-oriented programming approach, write a Java program that computes and outputs the area of the shaded region in the diagram.

-          Define a class Circle (Circle.java)

o   One private data member: radius;

o   Two overloaded constructors;

o   Get and set methods for the private data member;

o   Method computeArea which computes and returns the area;

o   Method computeCircumference which computes and returns the circumference;

o   toString() method.

-          Define a class Trapezoid (Trapezoid.java)

o   Three private data members: base1, base2, and height;

o   Two overloaded constructors;

o   Get and set methods for each private data member;

o   Method computeArea which computes and returns the area;

o   toString() method.

-          (ShadedRegion.java) Write the client class that inputs a radius, a base1, a base2, and a height, then creates a Circle object and a Trapezoid object based on the user input, then uses these two objects to compute and output the shaded area (you can assume that the circle is smaller enough to fit inside the trapezoid).

Explanation / Answer

import java.text.DecimalFormat;

public class Circle extends Object
{

private double radius;
final double PI = 3.14159;

public Circle( )
{

setCircle(0);

}


public Circle(double rad)
{

setCircle(rad);

}


public void setCircle(double rad)
{

radius = rad;

}

public void setRadius(double rad)
{

radius = rad;

}

public double getRadius( )
{

return radius;

}


public double computeArea( Circle input )
{

return PI * this.getRadius( ) * this.getRadius( );

}

public double computeCircumference( Circle input )
{

return 2 * PI * this.getRadius( );

}

public String toPrecisionFourString(double someNumber)
{

DecimalFormat precisionFour = new DecimalFormat("0.0000");
return precisionFour.format(someNumber);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote