Java Slot Machine

Java Slot Machine

After you call keyboard.nextInt(), you must call keyboard.nextLine() to dump the newline character in the buffer. nextInt() reads until it finds something that cannot be part of an int and leaves everything after the int sitting in the buffer.

See this post for more information: Reading Strings next() and nextLine() Java

To get your code to work (with little changes):
Use; instead of keyboard.nextLine();

change your initial cont = n to cont = y, and have the while loop check if (cont.equals(y)).

This is a quick fix, there are many changes that could be made for efficiency and to keep up with standards, but I wont go into detail.

As for the under 30 lines requirement, I would start by using only one random generator to generate all 3 fruits in one structure. Ask yourself, why must you have separate random generators for each fruit? Why a new switch per fruit? One random vs 3 random generators, will produce the same randomness for your fruits.

Java Slot Machine

Leave a Reply

Your email address will not be published.