(A student recently asked for ideas for applications to write. This is one response to that request. I use this task in my ICS3C/3U course online, in Java. Dear students: you don’t need to complete this task.)
In many role-playing games, players develop new characters by rolling a die or dice a number of times.
Write an application with a graphical user interface which simulates this activity and displays the result.
The user decides two parameters:
- how many rolls to simulate
- how many sides each die has
For example, the user might want 10 rolls of a standard, six-sided die (called a d6, if you’re interested). The user might later want 300 rolls of a 10-sided die (you guessed it: d10).
You’ll design the interface as you see fit, as long as the results are displayed in a JTextArea in a column, like this:
Make sure you handle bad user input gracefully (e.g. your program shouldn’t crash if the user enters “potatoes” for the number of rolls to simulate).