|
@ -5,88 +5,152 @@ import java.util.Scanner; |
|
|
|
|
|
|
|
|
public class ProgrammMain { |
|
|
public class ProgrammMain { |
|
|
|
|
|
|
|
|
//Aufzurufende Funktionen |
|
|
|
|
|
|
|
|
|
|
|
// Karteikarten |
|
|
|
|
|
|
|
|
|
|
|
public static void Karteikarten(){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try (Scanner input = new Scanner(System.in)) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String[][] karteikarten = {{"Was ist die Hauptstadt von Deutschland?", "Berlin"}, |
|
|
|
|
|
{"Welches ist der größtes Planet in unserem Sonnensystem?", "Jupiter"}, |
|
|
|
|
|
{"Wer hat die Mona Lisa gemalt?", "Leonardo da Vinci"}, |
|
|
|
|
|
|
|
|
|
|
|
//Sonstige Fragen |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
int counter = 0; |
|
|
|
|
|
for (String[] karteikarte : karteikarten) { |
|
|
|
|
|
System.out.println(karteikarte[0]); |
|
|
|
|
|
String answer = input.nextLine(); |
|
|
|
|
|
if (answer.equalsIgnoreCase(karteikarte[1])) { |
|
|
|
|
|
System.out.println("Korrekt!"); |
|
|
|
|
|
counter++; |
|
|
|
|
|
} else { |
|
|
|
|
|
System.out.println("Leider falsch. Die richtige Antwort wäre: " + karteikarte[1]); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
System.out.println("Dein Punktestand ist " + counter + " von insgesamt " + karteikarten.length); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Aufzurufende Funktionen |
|
|
|
|
|
|
|
|
|
|
|
// Karteikarten |
|
|
|
|
|
|
|
|
|
|
|
public static void Karteikarten() { |
|
|
|
|
|
|
|
|
|
|
|
try (Scanner input = new Scanner(System.in)) { |
|
|
|
|
|
|
|
|
|
|
|
String[][] karteikarten = { { "Was ist die Hauptstadt von Deutschland?", "Berlin" }, |
|
|
|
|
|
{ "Welches ist der größtes Planet in unserem Sonnensystem?", "Jupiter" }, |
|
|
|
|
|
{ "Wer hat die Mona Lisa gemalt?", "Leonardo da Vinci" }, |
|
|
|
|
|
|
|
|
|
|
|
// Sonstige Fragen |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
int counter = 0; |
|
|
|
|
|
for (String[] karteikarte : karteikarten) { |
|
|
|
|
|
System.out.println(karteikarte[0]); |
|
|
|
|
|
String answer = input.nextLine(); |
|
|
|
|
|
if (answer.equalsIgnoreCase(karteikarte[1])) { |
|
|
|
|
|
System.out.println("Korrekt!"); |
|
|
|
|
|
counter++; |
|
|
|
|
|
} else { |
|
|
|
|
|
System.out.println("Leider falsch. Die richtige Antwort wäre: " + karteikarte[1]); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println("Dein Punktestand ist " + counter + " von insgesamt " + karteikarten.length); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Quizz |
|
|
// Quizz |
|
|
|
|
|
|
|
|
public static void Quizz() { |
|
|
|
|
|
Random rand = new Random(); |
|
|
|
|
|
try (Scanner scanner = new Scanner(System.in)) { |
|
|
|
|
|
String[][] questions = { |
|
|
|
|
|
{"Welche Farbe hat ein Bananen?", "A) Gelb", "B) Grün", "C) Blau", "D) Rot", "A"}, |
|
|
|
|
|
{"Wie viele Beine hat eine Spinne?", "A) 4", "B) 6", "C) 8", "D) 10", "C"}, |
|
|
|
|
|
{"Wer hat die Formel E=mc² entwickelt?", "A) Isaac Newton", "B) Albert Einstein", "C) Galileo Galilei", "D) Stephen Hawking", "B"}, |
|
|
|
|
|
{"Welches ist der größte Planet im Sonnensystem?", "A) Merkur", "B) Venus", "C) Erde", "D) Jupiter", "D"} |
|
|
|
|
|
//Sonstige Fragen |
|
|
|
|
|
}; |
|
|
|
|
|
int questionIndex = rand.nextInt(questions.length); |
|
|
|
|
|
String[] currentQuestion = questions[questionIndex]; |
|
|
|
|
|
|
|
|
|
|
|
System.out.println(currentQuestion[0]); |
|
|
|
|
|
System.out.println(currentQuestion[1]); |
|
|
|
|
|
System.out.println(currentQuestion[2]); |
|
|
|
|
|
System.out.println(currentQuestion[3]); |
|
|
|
|
|
System.out.println(currentQuestion[4]); |
|
|
|
|
|
String answer = scanner.nextLine(); |
|
|
|
|
|
|
|
|
|
|
|
if (answer.equalsIgnoreCase(currentQuestion[5])) { |
|
|
|
|
|
System.out.println("Richtig!"); |
|
|
|
|
|
} else { |
|
|
|
|
|
System.out.println("Falsch!"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void Quizz() { |
|
|
|
|
|
Random rand = new Random(); |
|
|
|
|
|
try (Scanner scanner = new Scanner(System.in)) { |
|
|
|
|
|
String[][] questions = { |
|
|
|
|
|
{ "Welche Farbe hat ein Bananen?", "A) Gelb", "B) Grün", "C) Blau", "D) Rot", "A" }, |
|
|
|
|
|
{ "Wie viele Beine hat eine Spinne?", "A) 4", "B) 6", "C) 8", "D) 10", "C" }, |
|
|
|
|
|
{ "Wer hat die Formel E=mc² entwickelt?", "A) Isaac Newton", "B) Albert Einstein", |
|
|
|
|
|
"C) Galileo Galilei", "D) Stephen Hawking", "B" }, |
|
|
|
|
|
{ "Welches ist der größte Planet im Sonnensystem?", "A) Merkur", "B) Venus", "C) Erde", |
|
|
|
|
|
"D) Jupiter", "D" } |
|
|
|
|
|
// Sonstige Fragen |
|
|
|
|
|
}; |
|
|
|
|
|
int questionIndex = rand.nextInt(questions.length); |
|
|
|
|
|
String[] currentQuestion = questions[questionIndex]; |
|
|
|
|
|
|
|
|
|
|
|
System.out.println(currentQuestion[0]); |
|
|
|
|
|
System.out.println(currentQuestion[1]); |
|
|
|
|
|
System.out.println(currentQuestion[2]); |
|
|
|
|
|
System.out.println(currentQuestion[3]); |
|
|
|
|
|
System.out.println(currentQuestion[4]); |
|
|
|
|
|
String answer = scanner.nextLine(); |
|
|
|
|
|
|
|
|
|
|
|
if (answer.equalsIgnoreCase(currentQuestion[5])) { |
|
|
|
|
|
System.out.println("Richtig!"); |
|
|
|
|
|
} else { |
|
|
|
|
|
System.out.println("Falsch!"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Prinmbis100 |
|
|
// Prinmbis100 |
|
|
public static void PrimBis100() { |
|
|
|
|
|
for (int i = 2; i <= 100; i++) { |
|
|
|
|
|
boolean isPrime = true; |
|
|
|
|
|
for (int j = 2; j < i; j++) { |
|
|
|
|
|
if (i % j == 0) { |
|
|
|
|
|
isPrime = false; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (isPrime) { |
|
|
|
|
|
System.out.print(i + " "); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void PrimBis100() { |
|
|
|
|
|
for (int i = 2; i <= 100; i++) { |
|
|
|
|
|
boolean isPrime = true; |
|
|
|
|
|
for (int j = 2; j < i; j++) { |
|
|
|
|
|
if (i % j == 0) { |
|
|
|
|
|
isPrime = false; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (isPrime) { |
|
|
|
|
|
System.out.print(i + " "); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Binärinverter |
|
|
|
|
|
|
|
|
|
|
|
public static void Binaerrechner() { |
|
|
|
|
|
|
|
|
|
|
|
try (Scanner scanner = new Scanner(System.in)) { |
|
|
|
|
|
System.out.print("Gebe den ersten Binärcode ein: "); |
|
|
|
|
|
String binaryCode1 = scanner.nextLine(); |
|
|
|
|
|
System.out.print("Gebe den zweiten Binärcode ein: "); |
|
|
|
|
|
String binaryCode2 = scanner.nextLine(); |
|
|
|
|
|
System.out.print("Gebe die gewünschte Operation ein (+, -, *, /): "); |
|
|
|
|
|
char operation = scanner.next().charAt(0); |
|
|
|
|
|
|
|
|
|
|
|
int result = calculate(binaryCode1, binaryCode2, operation); |
|
|
|
|
|
System.out.println("Das Ergebnis ist: " + result); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static int calculate(String binaryCode1, String binaryCode2, char operation) { |
|
|
|
|
|
|
|
|
|
|
|
int decimal1 = binaryToDecimal(binaryCode1); |
|
|
|
|
|
int decimal2 = binaryToDecimal(binaryCode2); |
|
|
|
|
|
|
|
|
|
|
|
int result = 0; |
|
|
|
|
|
switch (operation) { |
|
|
|
|
|
case '+': |
|
|
|
|
|
result = decimal1 + decimal2; |
|
|
|
|
|
break; |
|
|
|
|
|
case '-': |
|
|
|
|
|
result = decimal1 - decimal2; |
|
|
|
|
|
break; |
|
|
|
|
|
case '*': |
|
|
|
|
|
result = decimal1 * decimal2; |
|
|
|
|
|
break; |
|
|
|
|
|
case '/': |
|
|
|
|
|
result = decimal1 / decimal2; |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
System.out.println("Ungültige Operation! Bitte wähle +, -, * oder /."); |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
return decimalToBinary(result); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static int binaryToDecimal(String binaryCode) { |
|
|
|
|
|
|
|
|
|
|
|
int decimal = 0; |
|
|
|
|
|
for (int i = binaryCode.length() - 1; i >= 0; i--) { |
|
|
|
|
|
char currentChar = binaryCode.charAt(i); |
|
|
|
|
|
if (currentChar == '1') { |
|
|
|
|
|
decimal += Math.pow(2, binaryCode.length() - i - 1); |
|
|
|
|
|
} else if (currentChar != '0') { |
|
|
|
|
|
System.out.println("Ungültiger Binärcode! Bitte gebe nur Nullen und Einsen ein."); |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return decimal; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static int decimalToBinary(int decimal) { |
|
|
|
|
|
int binary = 0; |
|
|
|
|
|
int power = 0; |
|
|
|
|
|
while (decimal > 0) { |
|
|
|
|
|
binary += (decimal % 2) * (int) Math.pow(10, power); |
|
|
|
|
|
decimal /= 2; |
|
|
|
|
|
power++; |
|
|
|
|
|
} |
|
|
|
|
|
return binary; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
public static void main(String[] args) { |
|
|
|
|
|
|
|
@ -99,35 +163,34 @@ public class ProgrammMain { |
|
|
|
|
|
|
|
|
try (Scanner einleser = new Scanner(System.in)) { |
|
|
try (Scanner einleser = new Scanner(System.in)) { |
|
|
int wahl = einleser.nextInt(); |
|
|
int wahl = einleser.nextInt(); |
|
|
switch(wahl) { |
|
|
|
|
|
|
|
|
switch (wahl) { |
|
|
case 1: |
|
|
case 1: |
|
|
Karteikarten(); |
|
|
Karteikarten(); |
|
|
break; |
|
|
break; |
|
|
case 2: |
|
|
case 2: |
|
|
Quizz(); |
|
|
Quizz(); |
|
|
//Funktion |
|
|
|
|
|
|
|
|
// Funktion |
|
|
break; |
|
|
break; |
|
|
case 3: |
|
|
case 3: |
|
|
PrimBis100(); |
|
|
PrimBis100(); |
|
|
//Funktion |
|
|
|
|
|
|
|
|
// Funktion |
|
|
break; |
|
|
break; |
|
|
case 4: |
|
|
case 4: |
|
|
System.out.println("Diese Funktion wird derzeit entwickelt! Hab bitte etwas Geduld oder sei kreativ und erstelle dir selber eine Funktion!"); |
|
|
|
|
|
//Funktion |
|
|
|
|
|
|
|
|
Binaerrechner(); |
|
|
|
|
|
// Funktion |
|
|
break; |
|
|
break; |
|
|
case 5: |
|
|
case 5: |
|
|
System.out.println("Diese Funktion wird derzeit entwickelt! Hab bitte etwas Geduld oder sei kreativ und erstelle dir selber eine Funktion!"); |
|
|
|
|
|
//Funktion |
|
|
|
|
|
|
|
|
System.out.println( |
|
|
|
|
|
"Diese Funktion wird derzeit entwickelt! Hab bitte etwas Geduld oder sei kreativ und erstelle dir selber eine Funktion!"); |
|
|
|
|
|
// Funktion |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
default: System.out.println("Ungültige Eingabe, versuche es bitte erneut!\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
|
System.out.println("Ungültige Eingabe, versuche es bitte erneut!\n"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println("Programm beendet\n"); |
|
|
System.out.println("Programm beendet\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |