Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

More Books

Students also viewed these Databases questions

Question

1. Why do people select some popular culture forms over others?

Answered: 1 week ago

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago