In: Computer Science
// the language is java, please implement the JOptionPane
Use method overloading to code an operation class called CircularComputing in which there are 3 overloaded methods and an output method as follows: • computeObject(double radius) – compute the area of a circle • computeObject(double radius, double height) – compute area of a cylinder • computeObject(double radiusOutside, double radiusInside, double height) – compute the volume of a cylindrical object • output() use of JOptionPane to display instance field(s) and the result of the computing
Code a driver class called CircluarComputingApp to run and test CircularComputing by calling each of these overloaded methods with hard-coded data and display the data and the result of the calculation by calling output() method. Must use required/meaningful names for fields, variables, methods and classes. May define more data and code more methods necessary/needed for practice Must document each of your source code
Program:
import java.util.*;
import javax.swing.*;
class CircularComputing
{
String output;
JFrame f1;
Scanner sc;
CircularComputing()
{
output="";
f1=new JFrame();
sc=new Scanner(System.in);
}
void computeObject(double radius)
{
output=output+"Radius : "+radius+"\n"+"Area of Circle:
"+Math.PI*radius*radius+"\n";
}
void computeObject(double radius, double height)
{
output=output+"Radius : "+radius+"\n";
output=output+"Height: "+height+"\n";
output=output+"Area of Cylinder:
"+Math.PI*radius*radius*height+"\n";
}
void computeObject(double radiusOutside, double radiusInside,
double height)
{
output=output+"Outer Radius : "+radiusOutside+"\n";
output=output+"Inside Radius : "+radiusInside+"\n";
output=output+"Height: "+height+"\n";
output=output+"Volume of Cylinder :
"+Math.PI*height*(radiusOutside*radiusOutside-radiusInside*radiusInside);
}
void output()
{
System.out.print("Enter a radius of a circle: ");
double rc=sc.nextDouble();
computeObject(rc);
output=output+"----------------------------------------------------\n";
System.out.print("Enter a radius of a cylinder: ");
double rcy=sc.nextDouble();
System.out.print("Enter a height of a cylinder: ");
double hcy=sc.nextDouble();
computeObject(rcy,hcy);
output=output+"----------------------------------------------------\n";
System.out.print("Enter 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();
computeObject(or,ir,h);
JOptionPane.showMessageDialog(f1,output);
}
}
class CircluarComputingApp
{
public static void main(String args[])
{
CircularComputing cc=new CircularComputing();
cc.output();
}
}
Output: