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 Implement Merge Sort
Language: Java Implement Merge Sort
Please use Java language in an easy way with comments! Thanks! Write a static method called...
Please use Java language in an easy way with comments! Thanks! 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...
Please use Java language in an easy way with comments! Thanks! Write a static method called...
Please use Java language in an easy way with comments! Thanks! 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...
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;...
USE JAVA PLEASE Use recursion to implement a method public static int indexOf(String text, String str)...
USE JAVA PLEASE Use recursion to implement a method public static int indexOf(String text, String str) that returns the starting position of the first substring of the text that matches str. Return –1 if str is not a substring of the text. For example, s.indexOf("Mississippi", "sip") returns 6. Hint: You must keep track of how far the match is from the beginning of the text. Make that value a parameter variable of a helper method.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT