Advertisement
Guest User

Program java

a guest
Jan 17th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.06 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. public class PolaFigur {
  6.     public static void main(String[] args) throws IOException {
  7.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  8.         boolean nieZatrzymano = true;
  9.         while (nieZatrzymano) {
  10.             System.out.println("Co bedziesz liczyl? 0 - pole 1 - obwod");
  11.             int coBedzieLiczone = Integer.parseInt(reader.readLine());
  12.             System.out.println(coBedzieLiczone);
  13.             System.out.println("Wybierz figure: ");
  14.             System.out.println("0  - kwadrat");
  15.             System.out.println("1 - trojkat");
  16.             System.out.println("2 - prostokat");
  17.             System.out.println("3 - trapez");
  18.             int numerFigury = Integer.parseInt(reader.readLine());
  19.             switch (numerFigury) {
  20.             case 0: {
  21.                 switch (coBedzieLiczone) {
  22.                 case 0: {
  23.                     int a;
  24.                     System.out.println("Podaj bok kwadratu");
  25.                     a = Integer.parseInt(reader.readLine());
  26.  
  27.                     double pole = a * a;
  28.                     System.out.println("Pole wynosi " + pole);
  29.                     break;
  30.                 }
  31.                 case 1: {
  32.                     int a;
  33.                     System.out.println("Podaj bok kwadratu");
  34.                     a = Integer.parseInt(reader.readLine());
  35.                     int obwod = 4 * a;
  36.                     System.out.println("obwod wynosi: " + obwod);
  37.                     break;
  38.                 }
  39.                 }
  40.                 break;
  41.             }
  42.             case 1: {
  43.                 switch (coBedzieLiczone) {
  44.                 case 0: {
  45.                     int a;
  46.                     int h;
  47.                     System.out.println("Podaj podstawe trojkata");
  48.                     a = Integer.parseInt(reader.readLine());
  49.                     System.out.println("Podaj wysokosc torjkata");
  50.                     h = Integer.parseInt(reader.readLine());
  51.                     double pole = a * h / 2;
  52.                     System.out.println("Pole wynosi " + pole);
  53.                     break;
  54.                 }
  55.                 case 1: {
  56.                     int a;
  57.                     int b;
  58.                     int c;
  59.                     System.out.println("Podaj bok a");
  60.                     a = Integer.parseInt(reader.readLine());
  61.                     System.out.println("Podaj bok b");
  62.                     b = Integer.parseInt(reader.readLine());
  63.                     System.out.println("Podaj bok c");
  64.                     c = Integer.parseInt(reader.readLine());
  65.                     int obwod = a + b + c;
  66.                     System.out.println("obwod wynosi: " + obwod);
  67.                     break;
  68.                 }
  69.                 }
  70.                 break;
  71.             }
  72.             case 2: {
  73.                 switch (coBedzieLiczone) {
  74.                 case 0: {
  75.                     int a;
  76.                     int b;
  77.                     System.out.println("Podaj bok a");
  78.                     a = Integer.parseInt(reader.readLine());
  79.                     System.out.println("Podaj bok b");
  80.                     b = Integer.parseInt(reader.readLine());
  81.                     double pole = a * b;
  82.                     System.out.println("Pole wynosi " + pole);
  83.                     break;
  84.                 }
  85.                 case 1: {
  86.                     int a;
  87.                     int b;
  88.                     System.out.println("Podaj bok a");
  89.                     a = Integer.parseInt(reader.readLine());
  90.                     System.out.println("Podaj bok b");
  91.                     b = Integer.parseInt(reader.readLine());
  92.  
  93.                     int obwod = 2 * a + 2 * b;
  94.                     System.out.println("obwod wynosi: " + obwod);
  95.                     break;
  96.                 }
  97.                 }
  98.                 break;
  99.             }
  100.             case 3: {
  101.                 switch (coBedzieLiczone) {
  102.                 case 0: {
  103.                     int a;
  104.                     int b;
  105.                     int h;
  106.                     System.out.println("Podaj pierwsza podstawe trapezu");
  107.                     a = Integer.parseInt(reader.readLine());
  108.                     System.out.println("Podaj druga podstawe trapezu");
  109.                     b = Integer.parseInt(reader.readLine());
  110.                     System.out.println("Podaj wysokosc trapezu");
  111.                     h = Integer.parseInt(reader.readLine());
  112.                     double pole = (a + b) * h / 2;
  113.                     System.out.println("Pole wynosi " + pole);
  114.                     break;
  115.                 }
  116.                 case 1: {
  117.                     int a;
  118.                     int b;
  119.                     int c;
  120.                     int d;
  121.                     System.out.println("Podaj bok a");
  122.                     a = Integer.parseInt(reader.readLine());
  123.                     System.out.println("Podaj bok b");
  124.                     b = Integer.parseInt(reader.readLine());
  125.                     System.out.println("Podaj bok c");
  126.                     c = Integer.parseInt(reader.readLine());
  127.                     System.out.println("Podaj bok d");
  128.                     d = Integer.parseInt(reader.readLine());
  129.                     int obwod = a + b + c + d;
  130.                     System.out.println("obwod wynosi: " + obwod);
  131.                     break;
  132.                 }
  133.                 }
  134.                 break;
  135.             }
  136.             default: {
  137.                 break;
  138.             }
  139.            
  140.             }
  141.             System.out.println("Czy chcesz kontynuowac (0 - nie, 1 lub inna liczba - tak)");
  142.             int czyKontynuowac = Integer.parseInt(reader.readLine());
  143.             if (czyKontynuowac ==0) nieZatrzymano = false;
  144.         }
  145.     }
  146.  
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement