Beginner Java enthusiast here.
I wanted to take a break from structured practice stuff and start with a blank page, and no help to write something of my own to test myself.
I had to learn about console().readLine() as I had not learned how to receive user input from the console. This lead me to parsing integers etc. I was able to build, and compile a program that did what I had envisioned, and did so perfectly! (if not a little clumsily...) However, I wanted to think outside the box, and see how I could use it in ways NOT intended and break it. Inputting anything but a number at the console (for instance typing P instead of 6) it throws an error because I only told it how to handle a number.
Long story short, I stretched past my knowledge and taught myself a lot, but could not find the answer I was looking for due to my lack of knowledge. If someone can even just tell me what to read up on, I am more than happy to do the learning myself, just need a nudge in the right direction.
Here is my program:
public class mysteryDoors{
public static void main(String[] args){
int doorOne = 1;
int doorTwo = 2;
int doorThree = 3;
System.out.println("Welcome contestant, to the Mystery Doors Game!");
System.out.println("Would you like to find out what is behind door number 1?");
System.out.println("Maybe door number 2?");
System.out.println("Or perhaps, door number 3?!");
int choice = Integer.parseInt(System.console().readLine("Please Choose a door..." ));
while (choice > 3){
System.out.println("I am sorry, please choose one of the available doors.");
int guess = Integer.parseInt(System.console().readLine("Please try again..." ));
choice = guess;
}
if (choice == 1){
System.out.println("Behind door number 1 is a wonderful sofa set!");
}
else if (choice == 2){
System.out.println("Behind door number 2 is a nice shiny silverware set!");
}
else if (choice == 3){
System.out.println("Behind door number 3 is a NEW CAR!");
}
}
}