#1 Write a java program which calculates the area of either a Triangle or a Rectangle. Use Scanner to take an input field to tell you if the area to be calculated is for a Triangle or is for a Rectangle. Depending on that input - the program must call either the Triangle method or the Rectangle method. Each of those methods must receive 2 input fields from the user - one for base and one for height in order to calculate the area and then to print that area and the height and base from inside the method.
Program File
AreaCalculator.java
// import the scanner class to read input from stdin
import java.util.Scanner;
class AreaCalculator {
public static double triangleArea(double length, double base){
// area of triangle is 0.5 * length * base
return 0.5 * length * base;
}
public static double rectangleArea(double length, double
width)
{
// area of rectangle is length * width
return length * width;
}
public static void main(String[] args) {
int userChoice;
double length;
// Intro message
System.out.println("***** Welcome to area calculator *****");
// scanner object to read input from stdin
Scanner scan = new Scanner(System.in);
System.out.println("Choose for what you want to calculate area\n1. Triangle\n2. Rectangle\n0. Exit");
// read user choice
userChoice = scan.nextInt();
switch(userChoice){
case 0:
System.exit(0);
break;
// When triangle is selected
case 1:
// read length from stdin
System.out.print("Enter the height of the triangle : ");
length = scan.nextDouble();
// read base from stdin
System.out.print("Enter the base of the triangle : ");
double base = scan.nextDouble();
// calculate area and print to stdout
System.out.println("The area of triangle is : " +
triangleArea(length, base));
break;
// when rectangle is selected
case 2:
// read length from stdin
System.out.print("Enter the height of the rectangle : ");
length = scan.nextDouble();
// read width from stdin
System.out.print("Enter the width of the rectangle : ");
double width = scan.nextDouble();
// calculate area and print to stdout
System.out.println("The area of rectangle is : " +
rectangleArea(length, width));
break;
default:
System.out.println("Invalid Entry!");
}
}
}


Output
***** Welcome to area calculator *****
Choose for what you want to calculate area
1. Triangle
2. Rectangle
0. Exit
1
Enter the height of the triangle : 10
Enter the base of the triangle : 10
The area of triangle is : 50.0

***** Welcome to area calculator *****
Choose for what you want to calculate area
1. Triangle
2. Rectangle
0. Exit
2
Enter the height of the rectangle : 10
Enter the width of the rectangle : 10
The area of rectangle is : 100.0

Hope this helps!
Please let me know if any changes needed.
Thank you!
Hope you're safe during the pandemic!
#1 Write a java program which calculates the area of either a Triangle or a Rectangle....
Write a Java program that prompts user to select one of the five shapes(Rectangle, Square, Triangle, Circle, and Parallelogram), then calculate area of the shape,must have input validation and uses more of java library like math class, wrapper class, string methods, use formatted output with the printf method. Finally, create a pseudo-code statement and flowchart
In Java Exercise #2: (Java) Design and implement a program (name it ComputeAreas) that defines four methods as follows: Method squareArea (double side) returns the area of a square. Method rectangleArea (double width, double length) returns the area of a rectangle. Method circleArea (double radius) returns the area of a circle. Method triangleArea (double base, double height) returns the area of a triangle. In the main method, test all methods with different input value read from the user. Document your...
JAVA Code Requried Copy the file java included below. This program will compile, but, when you run it, it doesn’t appear to do anything except wait. That is because it is waiting for user input, but the user doesn’t have the menu to choose from yet. We will need to create this. Below the main method, but in the Geometry class, create a static method called printMenu that has no parameter list and does not return a value. It will...
IN JAVA Overview In this project you will implement a Java program that will print several shapes and patterns according to uses input. This program will allow the use to select the type (say, rectangle, triangle, or diamond), the size and the fill character for a shape. All operations will be performed based on the user input which will respond to a dynamic menu that will be presented. Specifically, the menu will guide the user to decide between different forms...
JAVA
1. Write a class called Rectangle that represents a rectangular two-dimensional region. Your Rectangle objects should have the following fields and methods: int width, int height Where width and height are the dimensions of the rectangle. Write accessor methods (i.e. getWidth(), getHeight()) that retrieve the values stored in the fields above. And mutator methods (i.e. setWidthl), setHeight() ) that change the field's values. Finally create a method called getAreal) that returns the area of the rectangle. Like we did...
Q2) Interface Create a program that calculates the perimeter and the area of any given 2D shape. The program should dynamically assign the appropriate calculation for the given shape. The type of shapes are the following: • Quadrilateral 0 Square . Perimeter: 4xL • Area:LXL O Rectangle • Perimeter: 2(L+W) • Area:LxW Circle Circumference: I x Diameter (TT = 3.14) Area: (TT xD')/4 Triangle (assume right triangle) o Perimeter: a+b+c O Area: 0.5 x base x height (hint: the base...
Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate rectangle area. Some requirements: 1. User Scanner to collect user input for length & width 2. The formula is area = length * width 3. You must implement methods getLength, getWidth, getArea and displayData ▪ getLength – This method should ask the user to enter the rectangle’s length and then return that value as a double ▪ getWidth – This method should ask the...
I'm trying to write a program in C that calculates the area of a rectangle. I need to have a function that gets dimensions from a user and stores them with pointers and addresses and another function that calculates the area... my question is how do i access that values from the dimension function so that I can use it in my calculation and main function.. for example. void userDimensions(float *base, float *height){ scanf("%lf" , base); scanf("%lf", height); } float...
Problem: Given information about a circle, rectangle and a triangle, calculate the area of the shape from the information supplied. Write pseudocode to solve this problem and write a Python program that asks the user to input the required information for a shape and then calculates the area of the shape. Geometry Calculator 1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle 3. Calculate the Area of a Triangle 4. Quit Enter your choice (1...
Question 4 Write a program that display the area of a triangle. The program calls the following two functions: .getBaseHeight - This function uses a reference parameter variables to accept a double arguments base and height. This function should ask the user to enter the triangle's buse and height. Input validation: base and height should be positive numbers. calArea - This function should accept the triangle's base and height as arguments and return the triangle's area. The area is calculated...