Advertisement
Exhabition

Back-up - Weektaak 4

Sep 26th, 2020
446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 3.87 KB | None | 0 0
  1.  
  2. import java.util.ArrayList;
  3. import java.util.Scanner;
  4.  
  5. public class ThirdElement {
  6.  
  7.     static ArrayList<String> birthdayNames = new ArrayList<>();
  8.     static ArrayList<Integer> dateDay = new ArrayList<>();
  9.     static ArrayList<Integer> dateMonth = new ArrayList<>();
  10.  
  11.     public static void main(String[] args) {
  12.         showMenu();
  13.     }
  14.  
  15.     public static void showMenu() {
  16.         System.out.println("\nVerjaardagskalender 0.1");
  17.         System.out.println("Kies een optie:");
  18.         System.out.println("    1. Verjaardag toevoegen");
  19.         System.out.println("    2. Verjaardag verwijderen");
  20.         System.out.println("    3. Alle verjaardagen zien");
  21.  
  22.         Scanner scanner = new Scanner(System.in);
  23.  
  24.         boolean promptAgain = true;
  25.         while (promptAgain) {
  26.             int inputOption = Integer.parseInt(scanner.nextLine());
  27.  
  28.             if (inputOption == 1 || inputOption == 2 || inputOption == 3) {
  29.                 if (inputOption == 1) {
  30.                     addBirthday();
  31.                 } else if (inputOption == 2) {
  32.                     removeBirthday();
  33.                 } else if (inputOption == 3) {
  34.                     viewBirthdays();
  35.                 }
  36.                 promptAgain = false;
  37.             } else {
  38.                 System.out.println("Sorry, volgens mij zei ik 1 t/m 3, niet " + inputOption);
  39.             }
  40.         }
  41.     }
  42.  
  43.     public static void addBirthday() {
  44.         Scanner scanner = new Scanner(System.in);
  45.  
  46.         System.out.println("Wie is er jarig?");
  47.         String inputPerson = scanner.nextLine();
  48.  
  49.         System.out.println("Op welke dag?");
  50.         int inputDay = Integer.parseInt(scanner.nextLine());
  51.  
  52.         System.out.println("Van welke maand?");
  53.         int inputMonth = Integer.parseInt(scanner.nextLine());
  54.  
  55.         birthdayNames.add(inputPerson);
  56.         dateDay.add(inputDay);
  57.         dateMonth.add(inputMonth);
  58.  
  59.         System.out.println("Verjaardag opgeslagen");
  60.         showMenu();
  61.     }
  62.  
  63.     public static void removeBirthday() {
  64.         Scanner scanner = new Scanner(System.in);
  65.         boolean canContinue = false;
  66.  
  67.         while (!canContinue) {
  68.             System.out.println("Welke verjaardag wil je verwijderen?");
  69.             String inputRemoval = scanner.nextLine();
  70.  
  71.             for (int i = 0; i < birthdayNames.size(); i++) {
  72.                 if (inputRemoval.toLowerCase().equals(birthdayNames.get(i).toLowerCase())) {
  73.                     birthdayNames.remove(i);
  74.                     dateDay.remove(i);
  75.                     dateMonth.remove(i);
  76.                     i--;
  77.  
  78.                     canContinue = true;
  79.                 }
  80.             }
  81.  
  82.             boolean wantsToRestart = false;
  83.             if (canContinue == false) {
  84.                 System.out.println(
  85.                         "Het lijkt erop dat die naam niet eerder ingevoerd is, wil je het opnieuw proberen? J of N");
  86.  
  87.                 while (!wantsToRestart) {
  88.                     String inputContinue = scanner.nextLine();
  89.                     System.out.println(inputContinue.toLowerCase());
  90.                     if (inputContinue.toUpperCase().equals("N")) {
  91.                         showMenu();
  92.                         break;
  93.                     } else if (inputContinue.toUpperCase().equals("J")) {
  94.                         wantsToRestart = true;
  95.                     } else {
  96.                         System.out.println("Sorry, dat verstond ik niet? Voer J of N in");
  97.                     }
  98.                 }
  99.             }
  100.         }
  101.  
  102.         System.out.println("Verjaardag verwijdered!");
  103.         showMenu();
  104.     }
  105.  
  106.     public static void viewBirthdays() {
  107.         if (birthdayNames.size() != 0) {
  108.             for (int i = 0; i < birthdayNames.size(); i++) {
  109.                 System.out.println(dateDay.get(i) + "-" + dateMonth.get(i) + " " + birthdayNames.get(i));
  110.             }
  111.         } else {
  112.             System.out.println("Sorry, er zijn geen verjaardagen ingevoerd");
  113.         }
  114.  
  115.         showMenu();
  116.     }
  117. }
  118.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement