Project #92142 - Monopoly Game

28 Computer Tutors Online

Chapter Group Exercise

Creating Additional Classes for a Monopoly game

Section 4 of this chapter described the BoardSquare class, a class of objects for squares on a monopoly board. The NetBeans project Monopoly included with the files for this chapter, has that class and a public class named Monopoly with an executable main method.

Your task is to create a new class of objects for a player in a monopoly game, and to revise the public method in the Monopoly NetBeans project so that a player can move around the board. We are not implementing a complete monopoly game, but just creating a player class and testing how it works with the BoardSquare class.

The class discussion for this week is about this project. You may work with other students and communicate about the project through the class discussion, through email, or by meeting in person, to discuss the design and programming for this project, but each person should do his or her own work, writing his or her own code. You must participate in the class discussion. Your lab report should indicate who you worked with.

You should:

1. Design and create the class declaration for the player class according to the annotated UML diagram below, and add the class it to the NetBeans Monopoly project.

2. Modify the main() method in the Monopoly class so that the player moves around the board, as follows:

a. the player’s location will be the square that the player’s token is currently on.

b. the player’s location should start on Square zero, the Go square.

c. the computer should pick a random number beween 1 and 12 to simulate the roll of a pair of dice. It should pick two random numbers between 1 and 6 and add them together to ensure the same probability as rolling real dice.

d. The main method should then move the player to the new square by adding the random number to the number of the square the player is on, and set the player’s location to the new square. The squares are numbered 0 to 39, so whenever the new square number would go above 39 it should be reset (If newsquare > 39, then newsquare = newsquare – 39).

e. When a player arrives on a square:

i. the rent for the square should be subtracted from the player’s bank balance

ii. a message should be displayed (console or JoptionPane, it’s up to you) with

1. the name of the player

2. the name of the player’s token CSCI 111 Chapter 8 pg. 30

3. the roll of the dice

4. the name of the square the player is now on

5. the rent for the square, if it is not zero

6. the player’s new bank balance

The exact format of the message is up to you.

f. after a player has arrived on a square, the program should say “press enter to continue”, then use an input statement of some kind (keyboard scanner or inputDialog Window) to continue to the next turn.

g. The program should continue (loop) until the user stops the program, or the player’s bank balance is zero.

Remember, this is the first part in building a Monopoly game in Java so we are only testing the player class object moving around the board interacting with the BoardSquare class. Things like picking a card if the player lands on Chance, buying and selling properties, collecting $200 for passing Go, and so on, are not part of this project. In a real development situation, those things would be added in another phase of the project once the BoardSquare and Player objects work properly. Graphics (and sound) would also be added later. Don’t get carried away with fancy features at this point and make the assignment harder than it needs to be.