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

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...
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:...
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...
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...
The language is java Write a class called Tablet that stores information about a tablet's age,...
The language is java Write a class called Tablet that stores information about a tablet's age, capacity (in GB), and current usage (in GB). You should not need to store any more information Write actuators and mutators for all instance data Write a toString method When you print a tablet, the info should be presented as such: This tablet is X years old with a capacity of Y gb and has Z gb used. There is A gb free on...
Java programming. Write a public Java class called DecimalTimer with public method displayTimer, that prints a...
Java programming. Write a public Java class called DecimalTimer with public method displayTimer, that prints a counter and then increments the number of seconds. The counter will start at 00:00 and each time the number of seconds reaches 60, minutes will be incremented. You will not need to implement hours or a sleep function, but if minutes or seconds is less than 10, make sure a leading zero is put to the left of the number. For example, 60 seconds:...
Question(Design Java Method). There is a java code what created a "Student" class and hold all...
Question(Design Java Method). There is a java code what created a "Student" class and hold all the books owned by the student in the inner class "Book". Please propose a new method for the Student class so that given a Student object "student", a program can find out the title of a book for which student.hasBook(isbn) returns true. Show the method code and the calls to it from a test program. The Student class is following: import java.lang.Integer; import java.util.ArrayList;...
(In java language) Write an abstract class called House. The class should have type (mobile, multi-level,...
(In java language) Write an abstract class called House. The class should have type (mobile, multi-level, cottage, etc.) and size. Provide the following methods: A no-arg/default constructor. A constructor that accepts parameters. A constructor that accepts the type of the house and sets the size to 100. All other required methods. An abstract method for calculating heating cost. Come up with another abstract method of your own. Then write 2 subclasses, one for mobile house and one for cottage. Add...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT