Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | Apr 2017 |
Last Sign in: | 12 Weeks Ago, 3 Days Ago |
Questions Answered: | 4870 |
Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
MethodOverload:
Write a Java program, called MethodOverload that contains 5 static methods called area(). Each of these methods will calculate the area of a user inputted shape; they will take in different parameters as below. They should all return a double and calculate the area of the corresponding shape (formulas given):
The main method should take in user input to determine what shape the area needs to be calculated for. Depending on the shape given the program should then take in the correct parameters from the user (see Example below). Each input will be given in the order given in the descriptions above. You should also have an output if a non valid shape was entered. use "Not a valid shape!" as this message
(NOTE: you can use Math.PI to get the value of pi in Java)
Example:
- "Square 4" would determine that you are required to find the area of a square with a side length of 4.
- "Rectangle 4 4" would determine that you are required to find the area of a rectangle with width and height 4.
Input:
n x
where n is a string representing the shape, x is the number to go with the shape
Sample input :
Square 4
Output:
The area of a square with side of length 4
Sample output:
Area: 16.0