Question

In: Computer Science

REQUIREMENTS OF THE JAVA PROGRAM: Your task is to calculate geometric area for 3 shapes(square, rectangle...

REQUIREMENTS OF THE JAVA PROGRAM: Your task is to calculate geometric area for 3 shapes(square, rectangle and circle).

1. You need to build a menu that allows users to enter options. Possible options are 'S' for square, 'R' for rectangle and 'C' for circle. HINT: you can use switch statement to switch on string input

a. Invalid input should throw a message for the user. Example: Invalid input, please try again

2. Each options should ask users for relevant data. HINT: use scanner object to take in length for square, length/width for rectangle and radius for circle

a. At the class level store a constant variable for PI that cannot be changed. You can use 3.14 for the value

3. Each option should call relevant method that is created at the class level. Methods should take in input received from the users in the step above and return values. HINT: one method for square area calculation, one for rectangle area calculation and one for circle area calculation. Square and rectangle should return int, circle should return double

Expected output:
***Area Calculator***

S  --  Square

R  --  Rectangle

C  --  Circle

S

Please enter length of the square: 2

Area of your square is: 4

***Area Calculator***

S  --  Square

R  --  Rectangle

C  --  Circle

R

Please enter length of the rectangle: 2

Please enter length of the rectangle: 3

Area of your rectangle is: 6

***Area Calculator***

S  --  Square

R  --  Rectangle

C  --  Circle

C

Please enter the redius of the circle: 3

Area of your circle is: 28.26

Submissions:

PART 1 ==>> A flow chart showing the actions and logical decisions for the JAVA program. You can use any tool to draw the flow chart. Lucid chart is a good one and it has a free option. - https://app.lucidchart.com/users/register/personal?try=1

PART 2 ==>> The Java program itself

Rubrics:

  • Flowchart: 25 points
    • All actions covered - 15 points
    • All logical decisions covered - 10 points
  • Java program: 75 points
    • Program runs - 20 points
    • Program produces correct results -15 points
    • Menu is properly displayed - 5 points
    • Methods are well-defined and private - 10 points
    • PI is defined and private - 5 points
    • Meaningful names used for all variables, package and class - 10
    • Proper indentation and neatness of the program - 5
    • Appropriate comments - 5

Solutions

Expert Solution

1)flowchart:

2)Javaprogram:

// menudriven program for finding areas
import java.util.*;
import java.util.Scanner;
public class Main
{
// Declaring global varaible for PI value
public static double PI=3.14;
  
   public static void main(String[] args)
   {
   char choice;
   //Scanner class
   Scanner scann=new Scanner(System.in);
   // printing menu
   System.out.println("***Area Calculator***");
       System.out.println("S -- Square");
       System.out.println("R -- Rectangle");
       System.out.println("C -- Circle");
       // reading user choice
       choice=scann.next().charAt(0);
       while(true)
       {
      
   switch(choice)
   {
   // in case of square
       case 'S':
       {
       int length,Area;
       System.out.print("Please enter length of the square : ");
       length=scann.nextInt();
       // function calling for area of square
       Area=AreaSquare(length);
       System.out.println("Area of your square is : "+Area);
       break;
       }
       // in case of Rectangle
       case 'R':
       {
       int length,breadth,Area;
       System.out.print("Please enter length of the Rectangle : ");
       length=scann.nextInt();
           System.out.print("Please enter length of the Rectangle : ");
       breadth=scann.nextInt();
       // function calling for area of Rectangle
       Area=AreaRectangle(length,breadth);
       System.out.println("Area of your Rectangle is : "+Area);
       break;
       }
       //in case of circle
       case 'C':
       {
       int radius;
       double Area;
       System.out.print("Please enter radius of the circle : ");
       radius=scann.nextInt();
       // function calling for area of Circle
       Area=AreaCircle(radius);
       System.out.println("Area of your circle is : "+Area);
       break;
       }
       // default case
       default:
       {
       System.out.println("Invalid input, please try again");
       // exiting
       System.exit(0);
       }

   }
   // printing menu
   System.out.println("***Area Calculator***");
       System.out.println("S -- Square");
       System.out.println("R -- Rectangle");
       System.out.println("C -- Circle");
       // reading user choice
       choice=scann.next().charAt(0);

   }
   }
   // Method for area of square
   public static int AreaSquare(int length)
   {
   return length*length;
   }
   // method for area of Rectangle
   public static int AreaRectangle(int length,int breadth)
   {
   return length*breadth;
   }
   // metod for area of ClassCircularityError
   public static double AreaCircle(int radius)
   {
   return Main.PI*radius*radius;
   }
}


output:


Related Solutions

JAVA program: Calculate geometric area for 3 shapes(square, rectangle and circle). You need to build a...
JAVA program: Calculate geometric area for 3 shapes(square, rectangle and circle). You need to build a menu that allows users to enter options. Possible options are 'S' for square, 'R' for rectangle and 'C' for circle. HINT: you can use switch statement to switch on string input Invalid input should throw a message for the user. Example: Invalid input, please try again Each options should ask users for relevant data. HINT: use scanner object to take in length for square,...
Writing a Java Code Requirements of the JAVA program: Your task is to calculate geometric area...
Writing a Java Code Requirements of the JAVA program: Your task is to calculate geometric area for 3 shapes(square, rectangle and circle). You need to build a menu that allows users to enter options. Possible options are 'S' for square, 'R' for rectangle and 'C' for circle. HINT: you can use switch statement to switch on string input Invalid input should throw a message for the user. Example: Invalid input, please try again Each options should ask users for relevant...
Write a program to calculate the area of four shapes (Rectangle, triangle, circle and square). The...
Write a program to calculate the area of four shapes (Rectangle, triangle, circle and square). The program to present the user with a menu where one of the shapes can be selected. Based on the selection made, the user enters the proper input, the program validates the input (i.e all entries must be greater than zero). Once the input is entered and validated, the intended area is calculated and the entered information along with the area are displayed. Area of...
Write a Python program that represents various geometric shapes. Each shape like rectangle, square, circle, and...
Write a Python program that represents various geometric shapes. Each shape like rectangle, square, circle, and pentagon, has some common properties, ex. whether it is filled or not, the color of the shape, and number of sides. Some properties like the area of the shapes are determined differently, for example, area of the rectangle is length * widthand area of a circle is ??2. Create the base class and subclasses to represent the shapes. Create a separate test module where...
Write a Python program that represents various geometric shapes. Each shape like rectangle, square, circle, and...
Write a Python program that represents various geometric shapes. Each shape like rectangle, square, circle, and pentagon, has some common properties, ex. whether it is filled or not, the color of the shape, and number of sides. Some properties like the area of the shapes are determined differently, for example, area of the rectangle is length * widthand area of a circle is ??2. Create the base class and subclasses to represent the shapes. Create a separate test module where...
(In Java) Inheritance Shapes: Write 5 Classes: 1) Shapes    2) Triangle 3) Rectangle    4)...
(In Java) Inheritance Shapes: Write 5 Classes: 1) Shapes    2) Triangle 3) Rectangle    4) Circle 5) TestAllShapes (create 1 object of each type and print the Area for each of them.)
In java, implement a program that returns a value of the area of the geometric objects...
In java, implement a program that returns a value of the area of the geometric objects listed below. Use the technique of method overloading concept and also uses the interfaces for dynamic method invocation. Triangle: √?(? − ?)(? − ?)(? − ?) where s=(a+b+c)/2 a,b,c are the sides of the triangle. Square: A^2 where A is the side Rectangle: (a*b) where a ,b are sides Circle: ? = ??2 where r is the radius Cube: 6a^2 where a is the...
rite a program that will calculate the perimeter and area of a rectangle. Prompt the user...
rite a program that will calculate the perimeter and area of a rectangle. Prompt the user to input the length and width. Calculate the area as length * width. Calculate the perimeter as 2* length + 2* width. Display the area and perimeter. Please use a proper heading in a comment block (name, date, description of the program). Please use comments in your code. Run your program twice using different input. Copy the output and place it at the bottom...
The area of a particular rectangle is 12 times the area of a certain square, and...
The area of a particular rectangle is 12 times the area of a certain square, and the width of the rectangle is three times the length of a side of the square. The perimeter of the rectangle is 30 units greater than the perimeter of the square. Find the dimensiuons of both the rectangle and the square.
Write a Python module that contains functions to calculate the perimeter and area of at least 4 different geometric shapes.
Modules Assignment pythonWrite a Python module that contains functions to calculate the perimeter and area of at least 4 different geometric shapes.Write a separate Python program (in a separate file from you Python module) that imports your above module and uses several of its functions in your program. Make use of the input() and print() functions in this program file. Try to make your program as a real-world application.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT