Instructor: Trish Cornez


CS110 Programming Assignment 9 : Basics of Classes



Program 1


Create a class to model a circle. Name this class Circle.
  1. The class should include data members for radius, x and y.
  2. 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.
  3. Include setter/getter member methods for each data member.
  4. Include methods for computing the circumference and area.
Test this class by instantiating Circle objects as follows:



Program 2


Create a class to model a single playing card in a deck of cards. Name this class Card.
  1. The class should include data members for rank and suit. Note: Use integers to identify rank and suit. Suits can be specified using constants.
  2. Include an explicit constructor that receives a rank and suit value.
  3. Include setter/getter member methods for each data member.
  4. 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:

  1. In a game of craps a player, the craps shooter,throws two die.
  2. If the first throw (called the come-out roll) adds up to 2, 3, or 12, the player loses.
  3. If the come-out roll adds up to 7 or 11, the player wins!
  4. 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

  1. 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.
  2. Create a text file and store all game output in this file.
  3. Create a method, playGame, which plays a single game and returns 1 if the player wins and 0 if the player loses.
  4. 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.
  5. 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.