In: Computer Science
language is java
Use method overloading to code an operation class called CircularComputing in which there are 3 overloaded methods as follows:
computeObject(double radius)-compute area of a circle
computeObject(double radius, double height)-compute area of a cylinder
computeObject(double radiusOutside, double radiusInside, double height)-compute volume of a cylindrical object
These overloaded methods must have a return of computing result in each
Then override toString() method so it will return the object name, the field data, and computing result
Code a driver class called CircluarComputingApp to run and test CircularComputing by creating at least one object with hard-coded data for each type of the circular shapes and display the name of the shape, the data and the result of the calculation by calling toString() method.
Must use required/meaningful names for fields, variables, methods and classes
Must document each of your source code.
Program:
import java.util.*;
class CircularComputing
{
Scanner sc;
CircularComputing()
{
sc=new Scanner(System.in);
}
double computeObject(double radius)
{
System.out.println("Radius : "+radius);
return (Math.PI*radius*radius);
}
double computeObject(double radius, double height)
{
System.out.println("Radius : "+radius);
System.out.println("Height: "+height);
return(Math.PI*radius*radius*height);
}
double computeObject(double radiusOutside, double radiusInside,
double height)
{
System.out.println("Outer Radius : "+radiusOutside);
System.out.println("Inside Radius : "+radiusInside);
System.out.println("Height: "+height);
return(Math.PI*height*(radiusOutside*radiusOutside-radiusInside*radiusInside));
}
public String toString()
{
System.out.print("\nCircle:\n----------------------------------------------------\nEnter
a radius of a circle: ");
double rc=sc.nextDouble();
System.out.printf("Area of Circle:
%.2f\n",computeObject(rc));
System.out.println("----------------------------------------------------\n");
System.out.print("\nCylinder(Area):\n----------------------------------------------------\nEnter
a radius of a cylinder: ");
double rcy=sc.nextDouble();
System.out.print("Enter a height of a cylinder: ");
double hcy=sc.nextDouble();
System.out.printf("Area of Cylinder:
%.2f\n",computeObject(rcy,hcy));
System.out.println("----------------------------------------------------\n");
System.out.print("\nCylinder(Volume):\n----------------------------------------------------\nEnter
Outside radius of a cylinder: ");
double or=sc.nextDouble();
System.out.print("Enter Inside radius of cylinder: ");
double ir=sc.nextDouble();
System.out.print("Enter height of a cylinder: : ");
double h=sc.nextDouble();
System.out.printf("Volume of Cylinder:
%.2f\n",computeObject(or,ir,h));
System.out.println("----------------------------------------------------\n");
return "";
}
}
class CircluarComputingApp
{
public static void main(String args[])
{
CircularComputing cc1=new CircularComputing();
System.out.println(cc1);
}
}
Output: