Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.lang.Math;
- import java.util.ArrayList;
- import java.util.List;
- public class ShapeAreaCounter {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- List<Double> pola = new ArrayList<Double>();
- String shape;
- double a;
- double b;
- double c;
- double pi = Math.PI;
- System.out.println("Podaj nazwę figury której pole chcesz obliczyć:\nkoło, kwadrat, trapez, trójkąt");
- shape = scan.nextLine();
- do {
- if (shape.equals("koło")) {
- System.out.println("Podaj promień koła");
- a = scan.nextDouble();
- pola.add(pi * a * a);
- } else if (shape.equals("kwadrat")) {
- System.out.println("Podaj bok kwadratu");
- a = scan.nextDouble();
- pola.add(a * a);
- } else if (shape.equals("trapez")) {
- System.out.println("Podaj górną podstawę");
- a = scan.nextDouble();
- System.out.println("Podaj dolną podstawę");
- b = scan.nextDouble();
- System.out.println("Podaj wysokość");
- c = scan.nextDouble();
- pola.add((a + b) / 2 * c);
- } else if (shape.equals("trójkąt")){
- System.out.println("Podaj podstawę");
- a = scan.nextDouble();
- System.out.println("Podaj wysokość");
- b = scan.nextDouble();
- pola.add((a*b)/2);
- }
- } while (!shape.equals("wynik"));
- System.out.println("Wynik wynosi: " + pola);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement