Basic ideas for Java programs

14th August 2018

Recently, I posted my Java code for a very basic text-based calculator. The plan is to slowly build it up by adding more and more features to it over time. It's probably best to figure out what features I want next and then learn how to implement them as opposed to just trying to learn everything at once without actually developing anything. Below are some ideas currently or soon-to-be in motion. I'll keep things text-based initially to get the functionality going, and the GUI will be a later addition.

Calculator: This works by asking for a number, an operation, and another number and calculating the answer. So if you enter 5 as the first number, + as the operation and 4 as the second number, the program will print 9.0 to the console. Why the decimal place? Because the variables storing the numbers are of the type "double", meaning they can hold decimal numbers. A potential feature here is for the program to convert the answer to an "int" variable (integer, no decimals) if the decimal value is point zero. Also, since there is no GUI yet, there are no buttons to press on-screen; the user input is taken from the keyboard. So, when asked for a number, you could enter something that isn't a number, which will cause the program to crash because there is not yet any code in the program to handle that situation. Further enhancements may include operations like pi, formulas like Pythagoras' theorem, etc. But I'd rather not delve too much into that. GCSE Maths throwbacks aren't great.

Guessing game: You have to guess a number bewteen 1 and 10. You have three guesses. The program generates a random number between 1 and 10, and if your guess matches with it, you win. This is quite a plain and boring game to make, and I've actually already done it. But I bring it up because it helps to build the foundation for the Russian roulette game.

Russian roulette: This game is played in turns between the user and the computer. Fundamentally, it's an advanced version of the guessing game. The main difference is that it generates a random number between 1 and 6 instead of 1 and 10. That random number is generated to determine which chamber (first, second, third, fourth, fifth or sixth) will hold the bullet. Before a game, you can decide whether you want to spin the cylinder on each turn or not. If you decide to spin the cylinder on each turn, the random number is generated after each turn. If you decide to not spin the cylinder on each turn, the random number is generated once. Then, after each pull of the trigger, the number of the chamber that the person is on increases by one (when it gets to the sixth chamber, it'll go down to the first chamber on the following turn, unless the bullet is in the sixth chamber). If you only spin the cylinder at the start, the game will definitely end within six goes, whereas if you spin it each time, the game could potentially go on forever.