Java :: Aufgabe #99 :: Lösung #2
10 Lösungen

#99
Stein, Papier, Schere, Echse, Spock
Anfänger - Java
von Energy
- 24.09.2015 um 15:22 Uhr
Programmiere das Spiel Stein, Papier, Schere, Echse, Spock, sodass man selbst eine Figur auswählen kann und der Computer eine zufällige Figur auswählt. Ermittele dann, wer diese Partie gewonnen hat.
#2

von thet1983 (800 Punkte)
- 02.11.2015 um 15:58 Uhr

import java.util.Scanner; public class SchereSteinPapier { public static void main(String[] args) { int player; int computer; System.out.println("Bitte treffen Sie Ihre Auswahl:\n"); System.out.println("1) Schere\n2) Stein\n3) Papier\n4) Echse\n5)Spock\n"); Scanner s = new Scanner(System.in); player = s.nextInt(); playerObject(player); computer = (int)Math.random() * 3+1; compObject(computer); // spieler schere if(player == 1){ playerSchere(computer); }else if( player == 2){ playerStein(computer); } else if( player == 3){ playerPapier(computer); } else if(player == 4){ playerEchse(computer); } else { playerSpock(computer); } } /** * @param computer */ private static void playerSpock(int computer) { switch(computer){ case 1: System.out.println("Du gewinnst"); break; case 2: System.out.println("Du gewinnst"); break; case 3: System.out.println("Du verlierst"); break; case 4: System.out.println("Du verlierst"); break; case 5: System.out.println("Unentschieden"); break; default: System.out.println("Falsche Eingabe"); } } /** * @param computer */ private static void playerEchse(int computer) { switch(computer){ case 1: System.out.println("Du verlierst"); break; case 2: System.out.println("Du verlierst"); break; case 3: System.out.println("Du gewinnst"); break; case 4: System.out.println("Unentschieden"); break; case 5: System.out.println("Du gewinnst"); break; default: System.out.println("Falsche Eingabe"); } } /** * @param computer */ private static void playerPapier(int computer) { switch(computer){ case 1: System.out.println("Du verlierst"); break; case 2: System.out.println("Du gewinnst"); break; case 3: System.out.println("Unentschieden"); break; case 4: System.out.println("Du verlierst"); break; case 5: System.out.println("Du gewinnst"); break; default: System.out.println("Falsche Eingabe"); } } /** * @param computer */ private static void playerStein(int computer) { switch(computer){ case 1: System.out.println("Du gewinnst"); break; case 2: System.out.println("Unentschieden"); break; case 3: System.out.println("Du verlierst"); break; case 4: System.out.println("Du gewinnst"); break; case 5: System.out.println("Du verlierst"); break; default: System.out.println("Falsche Eingabe"); } } /** * @param computer */ private static void playerSchere(int computer) { switch(computer){ case 1: System.out.println("Unentschieden"); break; case 2: System.out.println("Computer hat mit Stein dein Schere geschliffen, Computer gewinnt"); break; case 3: System.out.println("Du gewinnst"); break; case 4: System.out.println("Du gewinnst"); break; case 5: System.out.println("Du verlierst"); break; default: System.out.println("Falsche Eingabe"); } } /** * @param player */ private static void playerObject(int player) { switch(player){ case 1: System.out.println("SCHERE"); break; case 2: System.out.println("STEIN"); break; case 3: System.out.println("PAPIER"); break; case 4: System.out.println("ECHSE"); break; case 5: System.out.println("SPOCK"); break; default: System.out.println("Falsche Eingabe"); } } /** * @param comp */ private static void compObject(int player) { switch(player){ case 1: System.out.println("SCHERE"); break; case 2: System.out.println("STEIN"); break; case 3: System.out.println("PAPIER"); break; case 4: System.out.println("ECHSE"); break; case 5: System.out.println("SPOCK"); break; default: System.out.println("Falsche Eingabe"); } } }
Kommentare:
Für diese Lösung gibt es noch keinen Kommentar
Seite 1 von 0
1