COMP1400 – Programming for Designers

Class announcements for Programming for Designers

COMP1400 – Programming for Designers random header image

Lab 7 – debugging

Posted by on August 25th, 2011 · Lab

For this project you will be debugging a simple ‘games portal’ program. You can download the program as a Bluej project here. The code is complete and compiles correctly but it has a number of bugs in it that mean it doesn’t work properly. It is your job to find them.

There are two classes Player and Game. A Player has a credit balance with which they can buy games. A player can play any game they own, generating a score. The game keeps track of the best score for every player who has ever played it.

The methods on Player are:

  • getName – returns the player’s name
  • getCredit – returns the player’s current credit
  • addCredit – adds credit to the player’s account
  • buyGame – allows a player to buy a game if they have enough credit (and do not already own the game)
  • ownsGame – returns whether the player owns the game

The methods on Game are:

  • getName – returns the game’s name
  • getCredit – returns the game’s purchase price
  • play – The specified player plays the game and gets a random score. If it is better than the player’s best score so far, it is added to the high-score list
  • getHighScore – get the best score for the specified player
  • getBestPlayer – return the player who has the top score for this game,

There are at least seven bugs in the code. Three on Player and four on Game. You need to:

  1. Read the code and try to understand what it is doing.
  2. Invent test cases to check that it works the way it is supposed to.
  3. When you find something wrong, try to find the nearest possible cases that work and fail.
  4. Step through the different cases in the Debugger to work out what is going wrong.
  5. Work out how to fix them.

Some of the bugs are trickier to find than others. Test the simpler parts of the code first, then work up to more difficult cases.

No Comments so far ↓

There are no comments yet...Kick things off by filling out the form below.

You must log in to post a comment.