Advertisement
shadowsofme

What's Wrong With My biggestWinners?

Mar 25th, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. public ArrayList <LotteryTicket> tickets;
  2. private double highWin = -1.00, highStateWin = -1.00;
  3. private LotteryTicket stateHighest = null, highest = null;
  4.  
  5. //------------------------------------------------------------------
  6. // Returns who won the most prize money for this drawing.
  7. //------------------------------------------------------------------
  8. public LotteryTicket getBiggestWinner(){
  9. makePayouts();
  10. highest = null;
  11. highWin = -1.00;
  12.  
  13. for(LotteryTicket t: tickets){
  14. // Checks to see if the ticket's prize is higher than the
  15. // current highest prize.
  16. if (t.getPrize() > highWin){
  17. // If the ticket's prize is higher than the current highest
  18. // prize, that ticket becomes the new highest prize winner.
  19. highWin = t.getPrize();
  20. highest = t;
  21. }
  22. }
  23.  
  24. // Returns the highest winning ticket.
  25. return highest;
  26. }
  27.  
  28. //------------------------------------------------------------------
  29. // Returns who won the most prize money in a given state for this
  30. // drawing.
  31. //------------------------------------------------------------------
  32. public LotteryTicket getBiggestStateWinner(String st){
  33. makePayouts();
  34. stateHighest = null;
  35. highStateWin = -1.00;
  36.  
  37. int stateCounter = 0;
  38. for(LotteryTicket t: tickets){
  39. // Checks to see if the ticket was filed in the entered state.
  40. if (t.getState().equalsIgnoreCase(st) == true){
  41. // Checks to see if the ticket's prize is higher than the
  42. // current highest prize.
  43. if (t.getPrize() > highStateWin){
  44. // If the ticket's prize is higher than the current highest
  45. // prize, that ticket becomes the new highest prize winner.
  46. highStateWin = t.getPrize();
  47. stateHighest = t;
  48. }
  49. // Adds 1 to the number of tickets found in the entered state,
  50. // whether it was highest or not.
  51. stateCounter++;
  52. }
  53. }
  54.  
  55. if (stateCounter == 0){
  56. // If no tickets were filed for the entered state,
  57. // the program will return null.
  58. return null;
  59. }else{
  60. // Otherwise, the program will return the highest
  61. // winning ticket for the entered state.
  62. return stateHighest;
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement