I've started a bachelor degree in a computer science related field so I ought to code and everything is quite new for me, but I guess we all started from scratch.
I'm having a hard time making my code function the way it should. I have to program a flip-coin game....create random number (even/odd), using user input and then the user should play as long as he wants, therefore I created a while-loop and it doesn't seem to work property. I already tried to put my code inside it and it didn't work neither. My IDE is also telling me that i never user the value assigned to my scanner.nextInt(), which is UserEingabe. I'm quite sure is something quite easy to solve for many of u but I'm struggling a bit. Thanks in advance for the help.
Code: Main class
class CoinObject {
public static void main(String[] args) {
Coin coinObject = new Coin();
coinObject.throwCoin();
}
}
Second class:
import java.util.Scanner;
public class Coin {
public void throwCoin(){
Scanner scanner = new Scanner(System.in);
System.out.println("Erraten sie, ob Kopf oder Zahl oben liegt:");
System.out.println("Kopf=0");
System.out.println("Zahl=1");
int UserEingabe = scanner.nextInt();
int randomNumber = (int) Math.random();
String yes = "yes";
String no = "no";
int spiele = 1;
int victories = 1;
String play = scanner.next();
// if the input = the random #, cool!, otherwise false :)
if (UserEingabe == randomNumber){
System.out.println("Sie haben richtig geraten");
System.out.println("Moechten Sie weiter spielen (yes/no)");
play = scanner.next();
} else {
System.out.println("Sie haben falsch geraten");
System.out.println("Moechten Sie weiter spielen (yes/no)");
play = scanner.next();
} if (UserEingabe != 0 || UserEingabe != 1){
System.out.println("falsche Eingabe, versuchen Sie wieder");
UserEingabe = scanner.nextInt();
}
// the loop will be repeat it as long as the player wants to play
while (play != no){
UserEingabe = scanner.nextInt();
if (play == yes){
System.out.println("Sie haben " + spiele + "Spiele gespielt und " + victories + "Spiele gewonnen");
victories=victories +1;
spiele = spiele+1;
}
}
}
}