Question DetailsNormal
$ 45.00
CSC201 - Project Number 2 | Complete Solution
Question posted by

CSC201 - Project Number 2

There are several things I want you to get out of this project:

    1. Use the code from the first project as a basis for this one. I will
        provide the sources for Die.java, PairOfDice.java, and Driver.java.

    2. Add a GUI component to the project to enable a player to roll the dice
        and to show images of the die that are rolled. I will supply the images
        of the die as part of the project.

        - Look at the code on page 151 thru 153 in the book to see how to
          manipulate images in Java. You call ImageIcon to create an "icon"that
          can be used by java from a graphic file and a JLabel to display the
          icon on a panel.

    3. Implement the "scoring" for a PigDice game:
       a. if two ones are rolled, a 2 is returned
       b. if one of the dice is a one, a 3 is returned

    4. Focus on the new scoring and displaying the images for the die after a
       roll, we will implement playing the game in the next project.

    5. Document your work
       a. Correct (or at least a neat) consistent comment format
       b. Create a UML diagram to "map out" the classes created and/or
          used by the project. I will provide a "starter" UML diagram. You need
            to fill in those pieces of the system classes (Math, String, JLabel,
            JPanel, etc.) that you use for the system.

    6. Use a consistent "style"
       a. white space
       b. indentation
       c. bracket style

You should read the "Csc201 style guide" rtf file and the "Csc201 UML guide"
pptx file, both which can be found in the Course Documents area of Blackboard,
prior to doing this project. Those documents set forth the elements I am
looking for and give you guidelines on how to accomplish these tasks.


As stated above, we are going to start adding a GUI component to the dice
program in order to play a real game, one called PigDice. You can read the
rules on page 265, PP 5.11 of the book. What we want to do is setup the dice
portion of the game and a basic GUI look and interface.

Your tasks are to:

    1. Add the ability to display the correct die image based on the facevalue
        of the die. Images are supplied as part of the project (see the zip file
        containing the die images).

    2. Change the output of two die roll so that:

        a. if both die show a one, output a 2 . . . by the rules of the "Pig"
            game, if a 2 is rolled, a player loses all of his points and gives
            up the dice.

        b. if one of the die shows a one, output a 3. Review the rules of the
            "Pig" game: if a one of the die is a one, the player forfeits the
            points for that round and gives up the dice.

    3. Show the output as divided into five areas: a title, an area for player 1,
        an area that shows the dice images, an area for player 2, and an area that
        shows the total of the two die after a roll.

            |                 The title of the program                   |
            |                                                            |
            |                     +---------------+                      |
            |                     + Press to roll +                      |
            |                     +---------------+                      |
            |                                                            |
            |   Player 1 area    | Dice Image area |   Player two area   |
            |                    |                 |                     |
            |                    |                 |                     |
            |                    |                 |                     |
            |                    |                 |                     |
            |                    |                 |                     |
            |                    |                 |                     |
            |                    |                 |                     |
            |                    |                 |                     |
            |                    |                 |                     |
            |                    |                 |                     |
            |                    |                 |                     |
            |                    |                 |                     |
            |             Message showing total from the roll            |

        To do this, you should use the BorderLayout() class that is shown in
        pages 356 to 358 in the book. That layout gives us areas labelled North,
        West, Center, East, and South . . . just what we want. Instead of
        JButtons in the various areas, as the book example shows, you will be
        using JPanels that you setup in your program.

        The two player areas are to be defined, but not used in this program.
        Remember, we are consentrating on the graphics piece for the die and
        the "pig" scoring.

All of the requirements below are in addition to the code given to you in the
Project2.zip file.

Die.java requirements:

    1. Implement the method getImage which returns an ImageIcon. The constructor
        for an ImageIcon can be found on page 151 of the book. Die.java will have
        to import java.swing.* in order to support the image icon.


    1.    PairOfDice will also need to return images for the two die. Let is call
        the two (two die, right!) getDie1Image() and getDie2Image(). Of course,
        you should use the getImage method from Die.java to implement these two

PigDie.java: A new source file

    Even though we have not covered it yet, this class will be created via
    inheritance from PairOfDice, as in:

        public class PigDie extends PairOfDice {

    That way, this class will have all of the methods defined in PairOfDice and
    will override the roll() method. The roll() method of PigDice must

    1. Return the value of 2 if each die comes up as a 1

    2. Return the value of 3 if one or the other of the die comes up as a 1

    3. Return the total value of the two die if the above two conditions are NOT

PigDicePanels.java: A new source file that sets up the panels, buttons, and
labels. Use the GUI homework programs as a model for what needs to be done
(creating panels, adding buttons, adding labels).

   1. Use the PigDie class to be able to roll the dice and get their images.

    2. Create the button to roll the dice via an ActionListener.

    3. Create a Title, Player 1, Dice, Player 2, and an output message panel.

    4. The die images are displayed via a JLabel, such as:

        imageLabel = new JLabel(myImageIcon); // can of course use a method that
                                              // returns an ImageIcon . . . hint hint

    5. Use a BorderLayout() class to create the output GUI. Again, see pages 356
        to 358 for an example using the BorderLayout class.

        UML note: BorderLayout() is built using aggregation (a bunch of
        JPanels). You will need to show that in your UML diagram.

    I'm leaving sizes up to you . . . you'll have to play with sizes to get
    things right. Hint: The center panel should be just a tad wider than the
    die images so that you can "stack" one image on top of the other.

PDriver.java: a new java source file that is the main program for this project

    1. creates a new JFrame

    2. Creates a PigDicePanels object

    3. Adds the panel to the frame

    4. packs and sets the frame visible.

    See the GUI homework for an example of code that does the above . . . you
    should use the source that divides the GUI code into two files . . .

Available Solution
$ 45.00
CSC201 - Project Number 2 | Complete Solution
  • This solution has not purchased yet.
  • Submitted On 04 Aug, 2015 12:56:47
Solution posted by
//throw this away public class Driv...
Buy now to view full solution.

$ 629.35