Question

In: Computer Science

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

Solutions

Expert Solution

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:


Related Solutions

// 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...
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.
in Java language, in most simple algorithm Using a stack class, write a static method called...
in Java language, in most simple algorithm Using a stack class, write a static method called parse that parses a String for balanced parentheses. we seek only to determine that the symbol ‘{‘ is balanced with ‘}’. parse accepts a single String parameter and returns an int. If parse returns a minus 1, then there are no errors, otherwise, parse should return the position within the String where an error occurred. For example parse(“{3 + {4/2} }”)   would return -1...
In Java Create a class called "TestZoo" that holds your main method. Write the code in...
In Java Create a class called "TestZoo" that holds your main method. Write the code in main to create a number of instances of the objects. Create a number of animals and assign a cage and a diet to each. Use a string to specify the diet. Create a zoo object and populate it with your animals. Declare the Animal object in zoo as Animal[] animal = new Animal[3] and add the animals into this array. Note that this zoo...
Language java Rewrite the method getMonthusing the "this" parameter CODE: import java.util.Scanner; public class DateSecondTry {...
Language java Rewrite the method getMonthusing the "this" parameter CODE: import java.util.Scanner; public class DateSecondTry { private String month; private int day; private int year; //a four digit number. public void writeOutput() { System.out.println(month + " " + day + ", " + year); } public void readInput() { Scanner keyboard = new Scanner(System.in); System.out.println("Enter month, day, and year."); System.out.println("Do not use a comma."); month = keyboard.next(); day = keyboard.nextInt(); year = keyboard.nextInt(); } public int getDay() { return day;...
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...
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...
Write a class in Java called 'RandDate' containing a method called 'getRandomDate()' that can be called...
Write a class in Java called 'RandDate' containing a method called 'getRandomDate()' that can be called without instantiating the class and returns a random Date between Jan 1, 2000 and Dec 31, 2010.
Write a Java class called Employee (Parts of the code is given below), which has three...
Write a Java class called Employee (Parts of the code is given below), which has three private fields firstName (String), lastName (String) and yearsEmployed (double). Implement accessor/mutator methods for the private fields and toString() method, that returns a String representation, which contains employee name and years she was employed. public class Employee { private String firstName; ... } Write a client program called EmployeeClient that creates an instance of Employee class, sets values for the fields (name: John Doe, yearsEmployed:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT