On this page:
5.1 Instructions
Practice Problems
Simon Says
A note about randomness
Submission notes
8.5

Assignment 5: Games, Equality for Unions

Goals: Design a game, explore the complexity of defining equality of two objects in a union.

Related files:
  Simon_Starter.java  

5.1 Instructions

Be very, very careful with naming! Again, the solution files expect your submissions to be named a certain way, so that they can define their own Examples class with which to test your code. Therefore, whenever the assignment specifies:
  • the names of classes,

  • the names and types of the fields within classes,

  • the names, types and order of the arguments to the constructor,

  • the names, types and order of arguments to methods, or

  • filenames,

...be sure that your submission uses exactly those names.

Make sure you follow the style guidelines that we enforce. For now the most important ones are: using spaces instead of tabs, indenting by 2 characters, following the naming conventions (data type names start with a capital letter, names of fields and methods start with a lower case letter), and having spaces before curly braces.

You will submit this assignment by the deadline using the online submission system. You may submit as many times as you wish. Be aware of the fact that close to the deadline the system may slow down to handle many submissions - so try to finish early.

There will be a separate submission for each problem - it makes it easier to grade each problem, and to provide you with feedback for each problem you work on.

The submissions will be organized as follows:

Due Date:
  • Thursday, February 23rd, 9:00pm

Practice Problems

Work out these problems on your own. Save them in an electronic portfolio, so you can show them to your instructor, review them before the exam, use them as a reference when working on the homework assignments.

Simon Says

Implement the game Simon Says. Simon Says is a memory game with four colors, where the game generates a random sequence of the colors and the player needs to replay those colors in order. On each successful playback, the game generates another color and lengthens the sequence. Some design suggestions:

A note about randomness

There are two ways to generate random numbers in Java. The easiest is to use Math.random(), which generates a double between 0 (inclusive) and 1 (exclusive). You can multiply this number by some integer to make it bigger, then coerce to an int to produce a random integer in the range you wish. However, this is not easily testable: you’ll get different random values every time.

The better way to generate random numbers is: First, import java.util.Random at the top of your file. Next, create a new Random() object, and use its nextInt(int maxVal) method, which will give you a random integer between zero (inclusive) and maxVal (exclusive).

This is known as a "pseudorandom number generator", since the numbers aren’t really random if they can be reliably repeated...

The reason this is better is because there is a second constructor, new Random(int initialSeed), which has the property that every time you create a Random with the same initial seed, it will generate the same "random" numbers in the same order every time your program runs. You should therefore design your world classes with two constructors:

Submission notes

Don’t make the game overly elaborate; we are more interested in your program’s design than your graphic design! Include two additional files in your submission:
  • UserGuide.txt should be a short file describing how to play the game.

  • Design.txt should describe each of the classes in your design, and what they all do. If you think it’s helpful, include an ASCII-art class diagram to show the relationships between the classes.

Be sure to include all your source files and all your image files in your submission, or else we won’t be able to run your game. You should submit the files as a single .zip file.