Question: import java.util.Scanner; public class Area { public static void main(String args[]) { Scanner in = new Scanner(System.in); System.out.print(Enter code(C for circle, R for rectangle, S

import java.util.Scanner;

public class Area {

public static void main(String args[]) { Scanner in = new Scanner(System.in); System.out.print("Enter code(C for circle, R for rectangle, S for square): "); char code = in.next().charAt(0);

if(code == 'C') { System.out.print("Enter radius: "); double radius = in.nextDouble(); System.out.println("Area of circle is " + (Math.PI * radius * radius)); } else if(code == 'R') { System.out.print("Enter width: "); double width = in.nextDouble(); System.out.print("Enter height: "); double height = in.nextDouble(); System.out.println("Area of rectangle is " + (width * height)); } else { System.out.print("Enter length of side: "); double side = in.nextDouble(); System.out.println("Area of square is " + (side * side)); } } }

Modify this program by building 3 methods(no arguments) that will do the work (input, calculations and output) for each of the 3 different figures. Then in the 3 if statements (or Switch stmt) that you have to determine which figure was selected, you should now only have to call the methods, which will then do the input, calculation and print the results. (Remember, you will need to use static for each of the methods that you build, since you will be calling them from the main method, which is also static.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!