Advertisement
WhipCored

Raffle

Jan 21st, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.14 KB | None | 0 0
  1. /**
  2.  *  Jenn Tillman
  3.  *  3112-051 Design and Implementation of Object-Oriented Systems
  4.  */
  5.  
  6. import java.util.ArrayList;
  7. import java.util.List;
  8.  
  9. import javax.swing.JOptionPane;
  10.  
  11. public class Raffle {
  12.     static List<Ticket> tickets = new ArrayList<Ticket>();
  13.  
  14.     public static void main (String[] args) {
  15.  
  16.         boolean isRightLength = false;
  17.         String winningNumber;
  18.        
  19.         //Accepts user input as string and parses to an integer value
  20.         do {
  21.                 winningNumber = JOptionPane.showInputDialog("Enter the winning 6-Digit ticket number");
  22.                 if (winningNumber == null || winningNumber.equals("")){
  23.                     JOptionPane.showMessageDialog(null,
  24.                             "The winning ticket number must have a value!",
  25.                             "Important!", JOptionPane.ERROR_MESSAGE);
  26.  
  27.                     //If user selects cancel, check to see if they wish to quit
  28.                     int value;
  29.                     value = JOptionPane.showConfirmDialog(null,
  30.                             "Do you want to quit?",
  31.                             "Please Confirm", JOptionPane.YES_NO_OPTION);
  32.                     if(value == JOptionPane.YES_OPTION){
  33.  
  34.                         System.exit(0);
  35.                     }else {
  36.                         continue;
  37.                     }
  38.  
  39.                 }
  40.  
  41.                 //Send winningTicket to Ticket Class
  42.                 new Ticket(winningNumber);
  43.  
  44.  
  45.                 //Checks if the length of the number is 6 digits, if not forces user to enter a value that is
  46.                 /*If winningNumber is Parsed to an int we need if (String.valueOf(winningTicketNumber).length() != 6)
  47.                     if winningNumber is kept as a String we need if(winningNumber.length() != 6)
  48.                 */
  49.                 if (winningNumber.length() != 6) {
  50.                     isRightLength = false;
  51.                     JOptionPane.showMessageDialog(null,
  52.                             "The winning ticket number must be 6 digits!",
  53.                             "Important!", JOptionPane.ERROR_MESSAGE);
  54.                 } else {
  55.                     isRightLength = true;
  56.                 }
  57.            }
  58.         while(!isRightLength);
  59.  
  60.  
  61.         //Boolean to check if there are still tickets to input
  62.         boolean stillTickets = true;
  63.  
  64.         //While Loop potentially to keep asking for information from user
  65.         while(stillTickets) {
  66.             String userName = JOptionPane.showInputDialog("Enter your name");
  67.             String userTicketNumber = JOptionPane.showInputDialog("Enter your ticket number");
  68.  
  69.             //Check if values are null, if they are let the user know this is not valid and continue loop
  70.             if (userName == null || userName.equals("") || userTicketNumber == null || userTicketNumber.equals("")) {
  71.  
  72.                 JOptionPane.showMessageDialog(null,
  73.                         "Ticket Holder's Name and/or Ticket Holder's ticket number cannot be null",
  74.                         "Important!", JOptionPane.ERROR_MESSAGE);
  75.                 continue;
  76.             }
  77.  
  78.             //Once there are valid values for userName and userTicketNumber Enter them into the Ticket Class
  79.             //Can also parseInt here if necessary
  80.             tickets.add(new Ticket(userName, userTicketNumber));
  81.            
  82.            
  83.             //Check if there are more tickets that need to be entered in
  84.             int result;
  85.             result = JOptionPane.showConfirmDialog(null,
  86.                     "Are there still tickets?",
  87.                     "Please Confirm", JOptionPane.YES_NO_OPTION);
  88.             if(result == JOptionPane.YES_OPTION){
  89.                 stillTickets = true;
  90.                
  91.             }else if(result == JOptionPane.NO_OPTION) {
  92.  
  93.                 stillTickets = false;
  94.                
  95.             }
  96.         }
  97.        
  98.         //Sends ticket list to Ticket class
  99.         new Ticket(tickets);
  100.        
  101.         Ticket x = new Ticket();
  102.         //Code calls to do calculations on Tickets in the Ticket Class
  103.         x.getFirstPlace();
  104.         x.getSecondPlace();
  105.         x.getThirdPlace();
  106.        
  107.  
  108.     }
  109.  
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement