Question
Write a Java Program that prompts the user to select the shape of the size and find it's area using different methods for each and
Write a Java Program that prompts the user to select the shape of the size and find it's area using different methods for each and every function. Each method should only do one function. User must be able to re-run the program.
SO FAR I'VE DONE THIS
import java.util.Scanner; public class Methods { public static void main(String [] args) { char Repeat = 'y'; do{ public static void Options() { Scanner u = new Scanner (System.in); int input; System.out.println("Enter 1 for the Area of Circle."); System.out.println("Enter 2 for the Area of Square."); System.out.println("Enter 3 for the Area of Rectangle."); input = u.nextInt(); Switch(input); } public static int Switch(int input) { switch(input) { case 1 : Scanner y = new Scanner (System.in); double side; System.out.println("Input the side of the Square."); side = y.nextDouble(); AreaSquare(side); outputAreaS(); case 2 : Scanner l = new Scanner (System.in); double radius; System.out.println("Input the radius of the Circle."); radius = l.nextDouble(); outputAreaC(); case 3 : Scanner p = new Scanner(System.in); double length; double width; System.out.println("Input the Length of the Rectangle."); length = p.nextDouble(); System.out.println("Input the Width of the Rectangle."); width = p.nextDouble(); outputAreaR(); default : System.out.println("You input is incorrect."); }} Scanner r = new Scanner(System.in); System.out.println("Do you want to run this program again? If yes press y or any key to exit."); Repeat = r.next().charAt(0); }}while(Repeat == 'y' || Repeat == 'Y'); public static void AreaSquare(double side) { double AreaS; AreaS = side * side; outputAreaS(AreaS); } public static void AreaCircle(double radius) { double AreaC; AreaC = (3.14) * radius * radius; outputAreaC(AreaC); } public static void AreaRectangle(double length, double width) { double AreaR; AreaR = length * width; outputAreaR(AreaR);
} public static void outputAreaS(double AreaS) { System.out.println("The area of Square is " + AreaS); } public static void outputAreaC(double AreaC) { System.out.println("The area of Circle is " + AreaC); } public static void outputAreaR(double AreaR) { System.out.println("The area of Rectangle is " + AreaR); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started