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...
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...
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:...
Java Language -Create a project and a class with a main method, TestCollectors. -Add new class,...
Java Language -Create a project and a class with a main method, TestCollectors. -Add new class, Collector, which has an int instance variable collected, to keep track of how many of something they collected, another available, for how many of that thing exist, and a boolean completist, which is true if we want to collect every item available, or false if we don't care about having the complete set. -Add a method addToCollection. In this method, add one to collected...
Java programming language should be used Implement a class called Voter. This class includes the following:...
Java programming language should be used Implement a class called Voter. This class includes the following: a name field, of type String. An id field, of type integer. A method String setName(String) that stores its input into the name attribute, and returns the name that was just assigned. A method int setID(int) that stores its input into the id attribute, and returns the id number that was just assigned. A method String getName() that return the name attribute. A method...
THE LANGUAGE IS JAVA Download the class ArrayManager.java and fill out the method shells with the...
THE LANGUAGE IS JAVA Download the class ArrayManager.java and fill out the method shells with the specifications below. After creating the methods 2) through 5), test them by running the application. The main method allows users to enter a command and, when necessary, additional command specifications. 1) a method displayArray: accepts as a parameter an int array named data prints the array elements to the console, separated by commas and spaces, with the entire array enclosed in braces, e.g., the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT