Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.59 KB | None | 0 0
  1. package monika.szpital;
  2.  
  3. public class Pacjent {
  4.  
  5.     private String name;
  6.     private String surName;
  7.     private long pesel;
  8.  
  9.     public Pacjent(String name, String surName, long pesel) {
  10.         this.name = name;
  11.         this.surName = surName;
  12.         this.pesel = pesel;
  13.     }
  14.  
  15.     public String getName() {
  16.         return name;
  17.     }
  18.  
  19.     public void setName(String name) {
  20.         this.name = name;
  21.     }
  22.  
  23.     public String getSurName() {
  24.         return surName;
  25.     }
  26.  
  27.     public void setSurName(String surName) {
  28.         this.surName = surName;
  29.     }
  30.  
  31.     public long getPesel() {
  32.         return pesel;
  33.     }
  34.  
  35.     public void setPesel(long pesel) {
  36.         this.pesel = pesel;
  37.     }
  38.  
  39.     @Override
  40.     public String toString() {
  41.         return name + " " + surName + " " + pesel;
  42.     }
  43. }
  44. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  45.  
  46. package monika.szpital;
  47.  
  48. import java.util.ArrayList;
  49. import java.util.List;
  50.  
  51. public class Hospital {
  52.  
  53.     private List<Pacjent> pacjentList;
  54.  
  55.     public Hospital() {
  56.         this.pacjentList = new ArrayList<>();
  57.     }
  58.  
  59.     public void addPacjet(Pacjent pacjent) {
  60.         this.pacjentList.add(pacjent);
  61.     }
  62.  
  63.     public void showPacjents() {
  64.         pacjentList.forEach(System.out::println);
  65.     }
  66. }
  67.  
  68. -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  69.  
  70. package monika.szpital;
  71.  
  72. import java.util.Scanner;
  73.  
  74. public class Applikacja {
  75.  
  76.     private Hospital hospital;
  77.  
  78.     private static final int EXIT = 0;
  79.     private static final int ADD = 1;
  80.     private static final int SHOW = 2;
  81.  
  82.     private Scanner scanner = new Scanner(System.in);
  83.  
  84.     public void run() {
  85.         hospital = new Hospital();
  86.  
  87.         while (true) {
  88.             System.out.println("Wybierz opcje :");
  89.             System.out.println("0 - wyjdz / 1 - dodaj pacjenta / 2 - wyswietl pacjentow");
  90.  
  91.             String chosen = scanner.nextLine();
  92.             switch (Integer.parseInt(chosen)) {
  93.                 case EXIT:
  94.                     System.exit(0);
  95.                     break;
  96.                 case ADD:
  97.                     System.out.println("podaj imie");
  98.                     String imie = scanner.nextLine();
  99.                     System.out.println("podaj nazwisko");
  100.                     String nazwisko = scanner.nextLine();
  101.                     System.out.println("podaj pesel");
  102.                     long pesel = scanner.nextLong();
  103.                     scanner.nextLine();
  104.                     hospital.addPacjet(new Pacjent(imie,nazwisko,pesel));
  105.                     break;
  106.                 case SHOW:
  107.                     hospital.showPacjents();
  108.                     break;
  109.                 default:
  110.                     System.out.println("zła wartość");
  111.             }
  112.         }
  113.     }
  114. }
  115.  
  116. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  117.  
  118. package monika.szpital;
  119.  
  120. public class Runnnn {
  121.  
  122.     public static void main(String[] args) {
  123.         new Applikacja().run();
  124.     }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement