Cash-back offer from May 7th to 12th, 2024: Get a flat 10% cash-back credited to your account for a minimum transaction of $50.Post Your Questions Today!

Question DetailsNormal
$ 45.00

CSC201 - Project Number 2 | Complete Solution

Question posted by
Online Tutor Profile
request

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.

Overview:

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.

PairOfDice.java

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

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

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
that

    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 Answer
$ 45.00

[Solved] CSC201 - Project Number 2 | Complete Solution

  • This solution is not purchased yet.
  • Submitted On 04 Aug, 2015 12:56:47
Answer posted by
Online Tutor Profile
solution
//throw this away public class Driv...
Buy now to view the complete solution
Other Similar Questions
User Profile
Exper...

CSC201 - Project Number 2 | Complete Solution

//throw this away public class Driver { public static void main(String[] args) { PigDicePanels dicePanels =new PigDicePanels(); } }...

The benefits of buying study notes from CourseMerits

homeworkhelptime
Assurance Of Timely Delivery
We value your patience, and to ensure you always receive your homework help within the promised time, our dedicated team of tutors begins their work as soon as the request arrives.
tutoring
Best Price In The Market
All the services that are available on our page cost only a nominal amount of money. In fact, the prices are lower than the industry standards. You can always expect value for money from us.
tutorsupport
Uninterrupted 24/7 Support
Our customer support wing remains online 24x7 to provide you seamless assistance. Also, when you post a query or a request here, you can expect an immediate response from our side.
closebutton

$ 629.35