Instructor: Trish Cornez
CS110 Programming Assignment 9 : Basics of Classes
Program 1
Create a class to model a circle. Name this class Circle.
- The class should include data members for radius, x and y.
- Include a default and explicit constructor. The explicit constructor will receive a
radius value and an x,y coordinate.
Make sure that the default constructor sets the radius to 1, x,y position to 1,1.
- Include setter/getter member methods for each data member.
- Include methods for computing the circumference and area.
Test this class by instantiating Circle objects as follows:
- Instantiate three Circle objects, c1, c2, and c3.
Use explicit values in the construction of c1 and c2.
Allow the default constructor to assign default values to c3.
- Use the setRadius() setter method to re-assign c1 a small radius value and
c2 a larger radius value.
- Do NOT re-assign the third circle a radius value; instead,
retain the value assigned at construction.
- Display all the values for all the Circle objects.
Program 2
Create a class to model a single playing card in a deck of cards. Name this class Card.
- The class should include data members for rank and suit.
Note: Use integers to identify rank and suit. Suits can be specified using constants.
- Include an explicit constructor that receives a rank and suit value.
- Include setter/getter member methods for each data member.
- Include a toString() member method that returns a string showing the rank and suit of the card.
Test this class by instantiating Card objects.
Construct a deck of cards as an array and fill it with 52 cards in a complete playing deck.
Shuffle the deck and deal 5 cards, displaying the rank and suit of each card dealt.
Program 3
From 1900 through the 1940's, the game of craps was a very popular game.
It was considered to be a "tough guy's" game and only required a set of dice.
Soldiers, sailors, and wiseguys liked the game because dice are small, you can
carry them anywhere, and because a game could last ten minutes or all night. Any
number of people could play, and the dice (and money) could disappear in a
moment if a mortar shell came arcing over or the police suddenly walked past.
By the 1990's, craps had nearly disappeared. The majority of gamblers
perferred to play slots and video poker; less that four percent of gamblers play
the dice. But an interesting trend has developed in the last few years. Gamblers
are rediscovering the pleasures of this dice game.
How to play the game of Craps:
- In a game of craps a player, the craps shooter,throws two die.
- If the first throw (called the come-out roll) adds up to 2, 3, or 12, the player loses.
- If the come-out roll adds up to 7 or 11, the player wins!
- If the player does not win or lose on the first roll, the player must continue throwing the dice
until they roll a 7 (which means they lose) or he/she matches their first roll (which means they win).
the game).
Guidelines
- In the main program, give the player $1000 to start. They must
continue playing the game (with the player first making a bet) until either the
player is broke or has obtained $2000.
- Create a text file and store all game output in this file.
- Create a method, playGame, which plays a single game and returns
1 if the player wins and 0 if the player loses.
- Create a method makeBet(), which handles the making of a bet. A
player can bet any amount from $1 to the amount of money on hand. Players cannot
bet more money than they have.
- Create a class called Dice. The only member method for this class should be tossDice.
Note: Each die within the can can have a value from 1 to 6. The value of a "throw" is the added
value of the two die.