Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ArrayList <LotteryTicket> tickets;
- private double highWin = -1.00, highStateWin = -1.00;
- private LotteryTicket stateHighest = null, highest = null;
- //------------------------------------------------------------------
- // Returns who won the most prize money for this drawing.
- //------------------------------------------------------------------
- public LotteryTicket getBiggestWinner(){
- makePayouts();
- highest = null;
- highWin = -1.00;
- for(LotteryTicket t: tickets){
- // Checks to see if the ticket's prize is higher than the
- // current highest prize.
- if (t.getPrize() > highWin){
- // If the ticket's prize is higher than the current highest
- // prize, that ticket becomes the new highest prize winner.
- highWin = t.getPrize();
- highest = t;
- }
- }
- // Returns the highest winning ticket.
- return highest;
- }
- //------------------------------------------------------------------
- // Returns who won the most prize money in a given state for this
- // drawing.
- //------------------------------------------------------------------
- public LotteryTicket getBiggestStateWinner(String st){
- makePayouts();
- stateHighest = null;
- highStateWin = -1.00;
- int stateCounter = 0;
- for(LotteryTicket t: tickets){
- // Checks to see if the ticket was filed in the entered state.
- if (t.getState().equalsIgnoreCase(st) == true){
- // Checks to see if the ticket's prize is higher than the
- // current highest prize.
- if (t.getPrize() > highStateWin){
- // If the ticket's prize is higher than the current highest
- // prize, that ticket becomes the new highest prize winner.
- highStateWin = t.getPrize();
- stateHighest = t;
- }
- // Adds 1 to the number of tickets found in the entered state,
- // whether it was highest or not.
- stateCounter++;
- }
- }
- if (stateCounter == 0){
- // If no tickets were filed for the entered state,
- // the program will return null.
- return null;
- }else{
- // Otherwise, the program will return the highest
- // winning ticket for the entered state.
- return stateHighest;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement