Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.73 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.lang.Math;
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. public class ShapeAreaCounter {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.         List<Double> pola = new ArrayList<Double>();
  9.         String shape;
  10.         double a;
  11.         double b;
  12.         double c;
  13.         double pi = Math.PI;
  14.         System.out.println("Podaj nazwę figury której pole chcesz obliczyć:\nkoło, kwadrat, trapez, trójkąt");
  15.         shape = scan.nextLine();
  16.         do {
  17.             if  (shape.equals("koło")) {
  18.                 System.out.println("Podaj promień koła");
  19.                 a = scan.nextDouble();
  20.                 pola.add(pi * a * a);
  21.             } else if (shape.equals("kwadrat")) {
  22.                 System.out.println("Podaj bok kwadratu");
  23.                 a = scan.nextDouble();
  24.                 pola.add(a * a);
  25.             } else if (shape.equals("trapez")) {
  26.                 System.out.println("Podaj górną podstawę");
  27.                 a = scan.nextDouble();
  28.                 System.out.println("Podaj dolną podstawę");
  29.                 b = scan.nextDouble();
  30.                 System.out.println("Podaj wysokość");
  31.                 c = scan.nextDouble();
  32.                 pola.add((a + b) / 2 * c);
  33.             } else if (shape.equals("trójkąt")){
  34.                     System.out.println("Podaj podstawę");
  35.                     a = scan.nextDouble();
  36.                     System.out.println("Podaj wysokość");
  37.                     b = scan.nextDouble();
  38.                     pola.add((a*b)/2);
  39.                 }
  40.             } while (!shape.equals("wynik"));
  41.             System.out.println("Wynik wynosi: " + pola);
  42.         }
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement