MDM4U – Writing a Versatile Dice Simulator (optional)


(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:

2
1
5
6
3
3
4
5
5
1

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).

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s