Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.management.openmbean.SimpleType;
- import java.awt.*;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Scanner;
- public class Test{
- public static void prostokat(List<Double> figura){
- Scanner odczyt = new Scanner(System.in);
- System.out.print("Podaj wymiar A:");
- figura.add(odczyt.nextDouble());
- System.out.print("Podaj wymiar B:");
- figura.add(odczyt.nextDouble());
- System.out.print("Wczytano poprawnie! \n");
- }
- public static void wyswietl(List<Double> figura){
- int i=0;
- while (i < (figura.size()-1)){
- System.out.print("Prostokąt " + (i+1) + ": " + figura.get(i) + " x " + figura.get(i+1) + "\n");
- i+=2;
- }
- if(figura.size()==0) System.out.print("Wcztaj prostokąt! \n");
- }
- public static void sum(List<Double> figura){
- double sum=0;
- int i=0;
- while (i < (figura.size()-1)){
- sum+=figura.get(i) * figura.get(i+1);
- i+=2;
- }
- System.out.print("Suma pól wszystkich prostokątów: " +sum+"\n");
- }
- public static void main(String[] args) {
- List<Double> figura = new LinkedList<Double>();
- int wybor=0;
- Scanner odczyt = new Scanner(System.in);
- while (wybor < 4) {
- System.out.println("MENU:");
- System.out.println("1. Wczytaj prostokąt");
- System.out.println("2. Wyświetl wszystkie prostokąty");
- System.out.println("3. Oblicz sumę pól wszystkich prostokątów");
- System.out.println("4. Zakończ");
- System.out.print("Podaj co chcesz zrobic:");
- wybor = odczyt.nextInt();
- switch(wybor){
- case 1:
- prostokat(figura);
- break;
- case 2:
- wyswietl(figura);
- break;
- case 3:
- sum(figura);
- break;
- default: System.out.print("Podałeś złą wartość!");
- }
- }
- if (wybor==4) System.exit(0);
- }
- }
Add Comment
Please, Sign In to add comment