Skip to content

Instantly share code, notes, and snippets.

@themellowj
Created May 6, 2020 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save themellowj/eada28ae746f5dc95dd815229454719f to your computer and use it in GitHub Desktop.
Save themellowj/eada28ae746f5dc95dd815229454719f 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 int playGame(int amountWon){
rounds.add(amountWon);
for(int i - 0 < array.length; ++i) {
if( <0 == && == )
return true;
}
// add for else for win and lost.
// if <0<
//adding
return amountWon;
}
// 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(){
// we are instantiating a interget array to be sized by the number of rounds
Integer[] roundsArray = new Integer [rounds.size()] ;
// we are getting the values of rounds and placing them into the array
for (int i = 0; rounds.size() > i;i++){
roundsArray[i] = rounds.get(i);
}
return roundsArray;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment