Ultra Geile Studenten Benutzer Oberfläche (UGSBO)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
4.5 KiB

  1. /**
  2. *
  3. */
  4. package com.ugsbo.entscheider;
  5. import java.util.Scanner;
  6. import java.util.*;
  7. /**
  8. * @author bruec
  9. *
  10. */
  11. public class Entscheider {
  12. /**
  13. * @param args
  14. */
  15. public static void main(String[] args) {
  16. System.out.println(ergebnis(29, 1, 1, 3, 2, 1, 1, 4));
  17. }
  18. public static String ergebnis(int a, int b, int c, int d, int e, int f, int g, int h) {
  19. int erg = (((a + b + c) * d) / (e + f + g)) - h;
  20. String hilfe = "";
  21. if (erg < 5)
  22. hilfe = "Ich kann doch nicht fuer dich entscheiden, dass musst du schon selber wissen.";
  23. if (erg >= 5 && erg < 15)
  24. hilfe = "Naja, dann geh halt nach Hause und ruh dich aus.";
  25. if (erg >= 15)
  26. hilfe = "Jetzt wieder gehen? Dann bist du doch voellig umsonst aufgestanden. Geh einfach hin.";
  27. return hilfe;
  28. }
  29. public static String fragen() {
  30. // Eingangsfrage
  31. System.out.println(
  32. "Du willst also wissen ob du in die Veranstaltung gehen sollst oder nicht? Gib 1 für Ja ein 0 für Nein.");
  33. int a = getAnInteger();
  34. if (a == 1 || a == 0) {
  35. if (a == 1) {
  36. System.out.println("Dann werde ich dir jetzt ein paar Fragen stellen");
  37. } else {
  38. return("Na dann halt nicht. Tschüssi.");
  39. }
  40. } else {
  41. if (a == 1) {
  42. System.out.println("Dann werde ich dir jetzt ein paar Fragen stellen");
  43. } else {
  44. return ("Na dann halt nicht. Tschüssi.") ;
  45. }
  46. }
  47. // zweite Frage
  48. System.out.println("Wie alt bist du?");
  49. int alter = getAnInteger();
  50. if (alter > 0) {
  51. System.out.println(alter);
  52. } else {
  53. while (alter <= 0) {
  54. System.out.println("Versuches es nochmal. Du musst mindestens 1 sein.");
  55. alter = getAnInteger();
  56. }
  57. }
  58. // dritte Frage
  59. System.out.println("Auf einer Skala von 1 bis 10 wie motiviert bist du?");
  60. int mot = getAnInteger();
  61. if (mot >= 1 && mot <= 10) {
  62. System.out.println(mot);
  63. } else {
  64. skalaTest(mot);
  65. System.out.println(mot);
  66. }
  67. // vierte Frage
  68. System.out.println("Hast du gefrühstückt? Bei Ja bitte 1 und bei Nein bitte 0");
  69. int fruehstueck = getAnInteger();
  70. if (fruehstueck == 1 || fruehstueck == 0) {
  71. System.out.println(fruehstueck);
  72. } else {
  73. pruefen(fruehstueck);
  74. System.out.println(fruehstueck);
  75. }
  76. // fuenfte Frage
  77. System.out.println("Hast du jemals ein Harry Potterbuch gelesen? Bei Ja bitte 1 und bei Nein bitte 0");
  78. int harry = getAnInteger();
  79. if (harry == 1 || harry == 0) {
  80. System.out.println(harry);
  81. } else {
  82. pruefen(harry);
  83. System.out.println(harry);
  84. }
  85. // sechste Frage
  86. System.out.println("Wie viele Äpfel hast du heute schon gegessen?");
  87. int apfel = getAnInteger();
  88. if (apfel > 0) {
  89. System.out.println(apfel);
  90. } else {
  91. while (apfel <= 0) {
  92. System.out.println("Versuches es nochmal. Die Zahl muss positiv sein.");
  93. apfel = getAnInteger();
  94. }
  95. }
  96. // siebte Frage
  97. System.out.println("Wie viele Veranstaltungen hattest du heute schon?");
  98. int anzahl = getAnInteger();
  99. if (anzahl > 0) {
  100. System.out.println(anzahl);
  101. } else {
  102. while (anzahl <= 0) {
  103. System.out.println("Versuches es nochmal. Die Zahl muss positiv sein.");
  104. anzahl = getAnInteger();
  105. }
  106. }
  107. // achte Frage
  108. System.out.println("Was würdest du statt der Vorlesung machen? Lernen? Bei Ja bitte 1 und bei Nein bitte 0");
  109. int lernen = getAnInteger();
  110. if (lernen == 1 || lernen == 0) {
  111. System.out.println(lernen);
  112. } else {
  113. pruefen(lernen);
  114. System.out.println(lernen);
  115. }
  116. if (lernen == 1)
  117. System.out.println("Wenn du das sagst, aber lueg dich doch bitte nicht selbst an.");
  118. // neunte Frage
  119. System.out.println("Wuerdest du dir ein gelbes Auto kaufen? Bei Ja bitte 1 und bei Nein bitte 0");
  120. int gelb = getAnInteger();
  121. if (gelb == 1 || gelb == 0) {
  122. System.out.println(gelb);
  123. } else {
  124. pruefen(gelb);
  125. System.out.println(gelb);
  126. }
  127. // Auswertung
  128. String antwort = ergebnis(alter, lernen, gelb, apfel, mot, harry, fruehstueck, anzahl);
  129. return antwort;
  130. }
  131. public static int skalaTest(int answer) {
  132. System.out.println("Try again. Nur Werte zwischen 1 und 10 sind erlaubt.");
  133. int b = getAnInteger();
  134. if (b >= 1 && b <= 10) {
  135. return b;
  136. }
  137. skalaTest(b);
  138. return -1;
  139. }
  140. public static int getAnInteger() {
  141. Scanner in = new Scanner(System.in);
  142. while (true) {
  143. try {
  144. return in.nextInt();
  145. } catch (InputMismatchException e) {
  146. in.next();
  147. System.out.println("Das ist kein Integer. Try again.");
  148. }
  149. }
  150. }
  151. public static int pruefen(int answer) {
  152. System.out.println("Try again. Nur 1 und 0 sind erlaubt.");
  153. int b = getAnInteger();
  154. if (b == 1 || b == 0) {
  155. return b;
  156. }
  157. pruefen(b);
  158. return 1;
  159. }
  160. }