Advertisement
Blonk

Untitled

Mar 16th, 2020
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.12 KB | None | 0 0
  1. import java.util.*;
  2. public class AreaCalculator{
  3.     public static void main(String[] args){
  4.     Scanner keyboard = new Scanner(System.in);
  5.     System.out.println("Shape Area Calculator version 0.1 (c) 2005 Mitchell Sample Output, Inc.");
  6.    
  7.     while(true){
  8.     System.out.println();
  9.     System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
  10.     System.out.println();
  11.     System.out.println("1) Triangle");
  12.     System.out.println("2) Rectangle");
  13.     System.out.println("3) Square");
  14.     System.out.println("4) Circle");
  15.     System.out.println("5) Quit");
  16.     System.out.print("Which shape: ");
  17.     int shape = keyboard.nextInt();
  18.     System.out.println();
  19.    
  20.     if(shape == 1){
  21.         area_triangle(5,6);
  22.     }else if(shape == 2){
  23.         area_rectangle(4,5);
  24.     }else if(shape == 3){
  25.         area_square(4);
  26.     }else if(shape == 4){
  27.         area_circle(4);
  28.     }else if(shape == 5){
  29.         quit();
  30.         break;
  31.     }
  32.     }}
  33.     public static double area_triangle(int base, int height){
  34.         Scanner keyboard = new Scanner(System.in);
  35.         System.out.print("Base: ");
  36.         base = keyboard.nextInt();
  37.         System.out.print("Height: ");
  38.         height = keyboard.nextInt();
  39.         System.out.println();
  40.         int A=(base*height)/2;
  41.         System.out.println("The area is "+A+".");
  42.         return A;
  43.     }
  44.     public static int area_rectangle(int length, int width){
  45.         Scanner keyboard = new Scanner(System.in);
  46.         System.out.print("Length: ");
  47.         length = keyboard.nextInt();
  48.         System.out.print("Width: ");
  49.         width = keyboard.nextInt();
  50.         System.out.println();
  51.         int A=length*width;
  52.         System.out.println("The area is "+A+".");
  53.         return A;
  54.     }
  55.     public static int area_square(int side){
  56.         Scanner keyboard = new Scanner(System.in);
  57.         System.out.print("Side: ");
  58.         side = keyboard.nextInt();
  59.         System.out.println();
  60.         int A=side*side;
  61.         System.out.println("The area is "+A+".");
  62.         return A;
  63.     }public static double area_circle(int radius){
  64.         Scanner keyboard = new Scanner(System.in);
  65.         System.out.print("Radius: ");
  66.         radius = keyboard.nextInt();
  67.         System.out.println();
  68.         double A=Math.PI*radius*radius;
  69.         System.out.println("The area is "+A+".");
  70.         return A;
  71.     }
  72.     public static String quit(){
  73.         System.out.println("GoodBye");
  74.         return null;
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement