I would like to separate the program below into two classes. When I tried to separate them, it didn't work. Please separate into two classes and give an explanation of the answer. Please paste screenshot of successful program run.    Program:   import java.util.Scanner; //for scanner class public class Geometry{  //method to calculate the area of a circle and return the area  public static double circleArea(double r){   double area = Math.PI * r * r; //calculate area   return area;  //return area  }     //method to calculate the area of a rectangle and return the area  public static double rectangleArea(double length, double width){      double area = length * width; //calculate area   return area;  //return area  }     //method to calculate the area of a triangle and return the area  public static double triangleArea(double base, double height){   double area = base * height * 0.5; //calculate area   return area;   //return area  }     //main method  public static void main(String[] args) {            Scanner sc = new Scanner(System.in); //Scanner object for input         double area;  //for area         int choice;   //for reading choice of user         //loop to print menu and loop will run until user want to exit         do {          //menu          System.out.println("\nGeometry Calculator\n");       System.out.println("   1. Calculate the Area of a Circle");       System.out.println("   2. Calculate the Area of a Rectangle");       System.out.println("   3. Calculate the Area of a Triangle");       System.out.println("   4. Quit");       System.out.print("\nEnter your choice (1-4): ");       choice = sc.nextInt();  //reading choice of user       System.out.println(); //new line       switch (choice) {        case 1: //if user choose option 1            System.out.print("Enter the Radius of a Circle = ");            double radius = sc.nextDouble();  //reading radius of a circle            area = circleArea(radius);  //calling method to calculate the area            System.out.println("The Area of a Circle = " + area); //print the area            break;        case 2: //if user choose option 2            System.out.print("Enter the Length of a Rectangle = ");            double length = sc.nextDouble();  //reading length of a rectangle            System.out.print("Enter the Width of a Rectangle = ");            double width = sc.nextDouble();  //reading width of a rectangle            area = rectangleArea(length, width); //calling method to calculate the area            System.out.println("The Area of a Rectangle = " + area); //print the area                    break;        case 3: //if user choose option 3            System.out.print("Enter the Base of a Triangle = ");            double base = sc.nextDouble();  //reading base of a triangle            System.out.print("Enter the Height of a Triangle = ");            double height = sc.nextDouble();  //reading height of a triangle            area = triangleArea(base, height);  //calling method to calculate the area            System.out.println("The Area of a Triangle = " + area); //print the area                    break;        case 4: //if user choose option 4            break;        default: //if user choose wrong option            System.out.println("Error! Enter valid choice...");       }         } while (choice != 4);  } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I would like to separate the program below into two classes. When I tried to separate them, it didn't work. Please separate into two classes and give an explanation of the answer. Please paste screenshot of successful program run. 

 

Program:

 

import java.util.Scanner; //for scanner class

public class Geometry{

 //method to calculate the area of a circle and return the area
 public static double circleArea(double r){
  double area = Math.PI * r * r; //calculate area

  return area;  //return area
 }

    //method to calculate the area of a rectangle and return the area
 public static double rectangleArea(double length, double width){
     double area = length * width; //calculate area

  return area;  //return area
 }

    //method to calculate the area of a triangle and return the area
 public static double triangleArea(double base, double height){
  double area = base * height * 0.5; //calculate area

  return area;   //return area
 }

    //main method
 public static void main(String[] args) {
  
        Scanner sc = new Scanner(System.in); //Scanner object for input

        double area;  //for area
        int choice;   //for reading choice of user

        //loop to print menu and loop will run until user want to exit
        do {

         //menu
         System.out.println("\nGeometry Calculator\n");
      System.out.println("   1. Calculate the Area of a Circle");
      System.out.println("   2. Calculate the Area of a Rectangle");
      System.out.println("   3. Calculate the Area of a Triangle");
      System.out.println("   4. Quit");
      System.out.print("\nEnter your choice (1-4): ");
      choice = sc.nextInt();  //reading choice of user

      System.out.println(); //new line

      switch (choice) {
       case 1: //if user choose option 1
           System.out.print("Enter the Radius of a Circle = ");
           double radius = sc.nextDouble();  //reading radius of a circle

           area = circleArea(radius);  //calling method to calculate the area

           System.out.println("The Area of a Circle = " + area); //print the area

           break;

       case 2: //if user choose option 2
           System.out.print("Enter the Length of a Rectangle = ");
           double length = sc.nextDouble();  //reading length of a rectangle

           System.out.print("Enter the Width of a Rectangle = ");
           double width = sc.nextDouble();  //reading width of a rectangle

           area = rectangleArea(length, width); //calling method to calculate the area

           System.out.println("The Area of a Rectangle = " + area); //print the area
       
           break;

       case 3: //if user choose option 3
           System.out.print("Enter the Base of a Triangle = ");
           double base = sc.nextDouble();  //reading base of a triangle

           System.out.print("Enter the Height of a Triangle = ");
           double height = sc.nextDouble();  //reading height of a triangle

           area = triangleArea(base, height);  //calling method to calculate the area

           System.out.println("The Area of a Triangle = " + area); //print the area
       
           break;

       case 4: //if user choose option 4
           break;

       default: //if user choose wrong option
           System.out.println("Error! Enter valid choice...");
      }

        } while (choice != 4);

 }
}

Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education