Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- while (true) {
- System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
- System.out.println("1) Triangle");
- System.out.println("2) Rectangle");
- System.out.println("3) Square");
- System.out.println("4) Circle");
- System.out.println("5) Quit");
- System.out.print("Please enter your shape selection: ");
- Scanner keyboard = new Scanner(System.in);
- int shapeOption = keyboard.nextInt();
- if (shapeOption == 1) {
- System.out.print("\nBase: ");
- Scanner keyboard2 = new Scanner(System.in);
- int base = keyboard2.nextInt();
- System.out.print("Height: ");
- Scanner keyboard3 = new Scanner(System.in);
- int height = keyboard3.nextInt();
- System.out.println("\nThe area is: " + area_triangle(base, height) + " square units");
- } else if (shapeOption == 2) {
- System.out.print("\nLength: ");
- Scanner keyboard4 = new Scanner(System.in);
- int length = keyboard4.nextInt();
- System.out.print("Width: ");
- Scanner keyboard5 = new Scanner(System.in);
- int width = keyboard5.nextInt();
- System.out.println("\nThe area is: " + area_rectangle(length, width) + " square units");
- } else if (shapeOption == 3) {
- System.out.print("\nSide length: ");
- Scanner keyboard6 = new Scanner(System.in);
- int side_length = keyboard6.nextInt();
- System.out.println("\nThe area is: " + area_square(side_length) + " square units");
- } else if (shapeOption == 4) {
- System.out.print("\nRadius: ");
- Scanner keyboard7 = new Scanner(System.in);
- int radius = keyboard7.nextInt();
- System.out.println("\nThe area is: " + area_circle(radius) + " square units");
- } else {
- System.out.println("\nGoodbye");
- break;
- }
- }
- }
- // returns the area of a circle
- public static double area_circle( int radius ){
- return Math.round((radius * radius * Math.PI)* 100.0) / 100.0;
- }
- // returns the area of a rectangle
- public static int area_rectangle( int length, int width ){
- return (length * width);
- }
- // returns the area of a square
- public static int area_square( int side ) {
- return (side * side);
- }
- // returns the area of a triangle
- public static double area_triangle( int base, int height ){
- return (0.5 * base * height);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement