You are on page 1of 3

CLASSES AND METHODS PROGRAMS

Be sure to include any pre and post conditions. Comment ALL classes thoroughly
and meet ALL programming expectations.
1.

Create a main class cleanGarage, which uses a class RoachPopulation


that simulates the growth of a roach population. The constructor
takes the size of the initial roach population. Also, create a default
constructor that sets the population to zero. The RoachPopulation class
should have the following methods:
a. waitForGrow (this methods simulates a 2.9% increase in the
population and returns the population)
b. spray (this method simulates spraying with insecticide, which reduces
the population by 10% and returns the population)
c. getRoaches (returns the current number of roaches)
d. toString will print out the object and return it
The garage starts with 10 roaches. Have your main class wait, spray, and
print the roach count for a ten period cycle.

2.

Create a main class BoxCars with a class called Die, which counts the
number of box cars (two sixes) that occur. The
constructor should set the die up to be sitting on
snake eyes to begin the rolling (each die starts at
1). The Die class should have the following
methods:
a. rollIt (this methods simulates and gets the new random number and
sets the face)
b. isBoxCar (this methods returns true if the die is a 6 and false
otherwise)
The main class should roll the two dice 1000 times. When done it should
print out the number of times, the boxcars occurred.

3.

Create a main class HouseCards that uses a class called


PlayingCard. The constructor should set up the suit (Clubs,
Diamonds, Hearts, or Spades) and the face value (2, 3, 4, 5,
6, 7, 8, 9, 10, Jack, Queen, King, or Ace). The PlayingCard
class should have the following methods:

a. flipIt (this method simulates the new card by generating a random


suit, and a face value)
b. isClubs(checks and returns whether the card was Clubs)
c. isDiamonds(checks and returns whether the card was Diamonds)
d. isHearts(checks and returns whether the card was Hearts)
e. isSpades(checks and returns whether the card was Spades)
f. toString (to print out the card)
The main class should deal 20 random cards, count the number of times a
Club, Diamond, Heart, or Spade occurs, and print out the card. After the 20
cards have been dealt, print the totals for each suit.
4.

Create a main class PlayPig that uses a class called PlayerDie. In this game,
the user competes against the computer. On each turn, the player rolls a
pair of dice and adds up his or her points. Whoever reaches 100 points first,
wins. If a player rolls a 1, he or she loses all points for that round and the
dice go to the other player. If a player rolls two 1s in a
turn, he loses all points in the entire game and loses
control of the dice. The player may voluntarily turn over
the dice after each roll. So the player must decide to
either roll again (be a pig) and risk losing point, or give
up the dice, possibly letting the other player win. Set up
the computer player so that it always gives up the dice after getting 20 or
more points in a round.
a. What will you need to know about each player? What do you need to
set-up in your constructor?
b. You will need to have the following methods
i. getTotalPoints (returns the totalPoints)
ii. getCurrentPoints (returns the currentPoints)
iii. addTotalPoints(take the current points when the person
choose to pass and add them to the totalyou
will also need to reset your currentPoints to 0)
iv. rollDice (this will generate the dice)
v. addPoints (this will add the points to the
current points)
vi. resetCurrent (this will clear the current points
on a pass or snakeEyes)
vii. snakeEye (checks if a 1 was rolled and clears the

currentPoints)
viii. doubleSnakeEyes (checks if 2 1s were rolled and clears the
currentPoints and the totalPoints)
ix. toString (which will print the users totalPoints and
currentPoints along with the computers totalpoints and
currentpoints)
x. You may choose to add any other methods that you deem
necessary
The main class should print running totals out for the user to see. What do
you need in your main class??
Hint
loop until the points are reached
loop for the human player

loop for the computer player

You might also like