Question

In: Computer Science

// the language is java, please implement the JOptionPane Use method overloading to code an operation...

// 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

Solutions

Expert Solution

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:


Related Solutions

language is java Use method overloading to code an operation class called CircularComputing in which there...
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...
Please use java language Thanks! Implement a recursive method called "pow" that takes 2 integers, x...
Please use java language Thanks! Implement a recursive method called "pow" that takes 2 integers, x and y, as parameters and returns the value xy (x raised to the power y). The exponent must be non-negative. If a negative argument is given for the exponent, then an exception should be thrown. Implement a recursive method called "fib" that takes a positive integer, n, as a parameter and returns the nth Fibonacci value. Assume that the first 2 values in the...
Write a short code segment which includes/illustrates the concepts of inheritance, overloading, and overriding in java language.
Write a short code segment which includes/illustrates the concepts of inheritance, overloading, and overriding in java language.
Please use Java language! With as many as comment! ThanksWrite a static method called "evaluate"...
In Java language Write a static method called "evaluate" that takes a string as a parameter. The string will contain a postfix expression, consisting only of integer operands and the arithmetic operators +, -, *, and / (representing addition, subtraction, multiplication, and division respectively). All operations should be performed as integer operations. You may assume that the input string contains a properly-formed postfix expression. The method should return the integer that the expression evaluates to. The method MUST use a stack...
Language: Java Design and implement a program that implements an Interpolation Search method. Interpolation search is...
Language: Java Design and implement a program that implements an Interpolation Search method. Interpolation search is similar to binary search, except it tries to begin the search nearer to the location of the item. Instead of the using the middle value of the sorted array, interpolation search estimates the location of the target with respect to the first & last values in the array. The implementation is the same as binary search except that you should calculate the mid value...
Please write a Java algorithm solving the following problem: Implement a Java method to check if...
Please write a Java algorithm solving the following problem: Implement a Java method to check if a binary tree is balanced. For this assignment, a balanced tree is defined to be a tree such that the heights of the two subtrees of any node never differ by more than one. 1. First, please create the following two classes supporting the Binary Tree Node and the Binary Tree: public class BinTreeNode<T> { private T key; private Object satelliteData; private BinTreeNode<T> parent;...
write a java code, please do not use method and demo Consider a four digit number...
write a java code, please do not use method and demo Consider a four digit number such as 6587. Split it at two digits, as 65 and 87. Sum of 65 and 87 is 152. Sum of the digits of 152 is 8. Given the starting and ending four digit numbers and a given target number such as 10, write a program to compute and print the number of instances where the sum of digits equals the target.
Language: Java I have written this code but not all methods are running. First method is...
Language: Java I have written this code but not all methods are running. First method is running fine but when I enter the file path, it is not reading it. Directions The input file must be read into an input array and data validated from the array. Input file format (500 records maximum per file): comma delimited text, should contain 6 fields: any row containing exactly 6 fields is considered to be invalid Purpose of this code is to :...
Please use the Java Programming language. This is the introductory course, chapter two. Please only use...
Please use the Java Programming language. This is the introductory course, chapter two. Please only use if/else if, else and while loop. We have not touch base with do and while do(I don't know if while do exist in Java). Create an application that converts number grades to letter grades. Console Welcome to the Letter Grade Converter Enter numerical grade: 90 Letter grade: A Continue? (y/n): y Enter numerical grade: 88 Letter grade: A Continue? (y/n): y Enter numerical grade:...
All code in JAVA please 1. Implement Insertion Sort 2. Implement Selection Sort *For problem 1...
All code in JAVA please 1. Implement Insertion Sort 2. Implement Selection Sort *For problem 1 and 2, please: a. Let the program generate a random array. b. Output both the original random array and the sorted version of it
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT