Skip to content

Instantly share code, notes, and snippets.

@jheidt
Forked from themellowj/wage
Last active May 6, 2020 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jheidt/963f6ca39d9362f27e0d5f0ac8002b03 to your computer and use it in GitHub Desktop.
Save jheidt/963f6ca39d9362f27e0d5f0ac8002b03 to your computer and use it in GitHub Desktop.
package McGriff;
import java.util.ArrayList;
// Justin
// Course CIS217
// Project 2
// 3/5/20
//
public class WageGamer {
//private fields
/** sum of winnings */
private int winnings;
/** sum of losses */
private int losses;
/** ArrayList of rounds */
//declaring arraylist
ArrayList < Integer > rounds;
//public methods:
//default constructor
public WageGamer() {
winnings = 0;
losses = 0;
// take no arguments
// instantiate the arraylist
rounds = new ArrayList < Integer > ();
}
// copy constructor
//takes an array of rounds and initializes the
// object by calling the default constructor
// then looping through the rounds and
//calling playgame (below)
// @param - pointSpread
public WageGamer(Integer[] rounds) { //wGamer only takes int in the array
this();
for (int round: rounds) { //for loop is best for array as you can assign the amount to amount in array
playGame(round);
}
}
//playGame(int amountWon)
public void playGame(int amountWon) {
rounds.add(amountWon);
if(amountWon > 0) {
// win
winnings += amountWon;
} elseif(amountWon < 0) {
// loss (is negative so dont subtract)
losses += amountWon;
} else {
// tie?
}
}
// numGames()
public int numGames() {
//rounds.add(numGames);
return rounds.size();
}
// @return the number of games played
// getWinnings()
// @return sum of winnings
public int getWinnings() {
//rounds.add(getWinnings);
return winnings;
}
// getLosses()
// @return sum of losses
public int getLosses() {
// rounds.add(getLosses);
return losses;
}
// getRounds()
// @return an array of Integers with the values from each round.
public Integer[] getRounds() {
Integer[] retAry = rounds.toArray(new Integer[rounds.size()]);
return retAry;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment