Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

i need help with these 2 Java Programs! 1. Enter the first side (as a decimal):

ID: 3806745 • Letter: I

Question

i need help with these 2 Java Programs!

1.

Enter the first side (as a decimal): 10.5
Enter the second side (as a decimal): 15.5
The area is 162.75
The perimeter is: 52.0

Should the user choose the circle (3)

Enter the radius (decimal): 30.2
The area is:2,865.2557
The circumference is: 189.752

Should the user choose the triangle:

Enter the height of the triangle (decimal): 3.0
Enter the base of the triangle (decimal): 4.0
The area is: 6.0
The perimeter is 12.0

When deciding on the data type to use for your sides (rectangle), radius (circle), base and height (triangle) consider how you will use them and the numeric types that will be used in the computations.

Declare PI as a named constant and assign it the value of 3.14159 at the time of declaration.

Notice that the example above strongly suggests that your program will require a series of interactions with the user in order to gather data for each set of shape calculations.

Assume you will be working with a right triangle (a triangle of 90 degrees).

Some calculations you may find useful:

for the perimeter of a rectangle:
perimeter = 2 * (side1 + side2)

for the circumference of a circle:
circumference = 2 * PI * radius

for the perimeter of a triangle:
perimeter = base + height + hypotenuse

to find the hypotenuse of the right triangle:
hyptenuse2 = base2 + height2

2.

A variation on the number sequence Fibonacci envisioned to solve that problem -- 0, 1, 1, 2, 3, 5... -- has become associated with definitions of beauty and ratios unrelated to mathematics (but as it turns out, very useful in Computer Science).

The problem reads:

Prompt the user for the number of values in Fibonacci the user wants to see. The sequence may be produced by using the last two values in the sequence to produce the next value. Start the sequence with 0 and 1. The next value in the sequence would be 1 (= 0 + 1). The next value would be 2 (= 1 + 1) and the value following would be 3 (= 1 + 2).

A typical session might look like this...

How many Fibonacci numbers do you want to see? 9

The Fibonacci sequence for 9 numbers is...
0, 1, 1, 2, 3, 5, 8, 13, 21

Explanation / Answer

Hi, Please find my implementation.

I have implemented Q1.

Please repost other in separate post

Please let me know in case of any issue.

import java.util.Scanner;

public class GeometricAreaPerimeterCalc {

   /**

   * this methods show the list of choice

   */

   public static void printMenu(){

       System.out.println("1. Rectangle");

       System.out.println("2. Circle");

       System.out.println("3. Triangle");

       System.out.println("4. Quit");

   }

   public static void main(String[] args) {

       Scanner sc = new Scanner(System.in);

       int c;

       while(true){

           printMenu();

           c = sc.nextInt();

           if(c == 4)

               break;

           if(c == 2){

               System.out.print("Enter the radius (decimal): ");

               double radius = sc.nextDouble();

               double area = 3.14*radius*radius;

               double perimeter = 2*3.14*radius;

               System.out.printf("The area is: %.2f ",area);

               System.out.printf("The circumference is: %.2f ",perimeter);

           }

           else if(c == 3){

               System.out.print("Enter the base of the triangle (decimal): ");

               double base = sc.nextDouble();

               System.out.print("Enter the height of the triangle (decimal): ");

               double height = sc.nextDouble();

               double area = 0.5*base*height;

               double hyp = Math.sqrt(base*base + height*height);

               double perimeter = height + base + hyp;

               System.out.printf("The area is: %.2f ",area);

               System.out.printf("The perimeter is: %.2f ",perimeter);

           }

           else if(c == 1){

               System.out.print("Enter the first side (as a decimal): ");

               double width = sc.nextDouble();

               System.out.print("Enter the second side (as a decimal): ");

               double height = sc.nextDouble();

               double area = width*height;

               System.out.printf("The area is: %.2f ",area);

               System.out.printf("The perimeter is: %.2f ",(2*(width + height)));

           }

           else

               System.out.println("Invalid input!!");

       }

   }

}

/*

Sample run:

1. Rectangle

2. Circle

3. Triangle

4. Quit

1

Enter the first side (as a decimal): 10.5

Enter the second side (as a decimal): 15.5

The area is: 162.75

The perimeter is: 52.00

1. Rectangle

2. Circle

3. Triangle

4. Quit

4

*/