Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. package h02;
  2.  
  3. public class LotteryTicket {
  4.  
  5.     /**
  6.      * Holds information about tickets status.
  7.      *
  8.      */
  9.     private boolean isValid = true;
  10.     /**
  11.      * Tickets nr1.
  12.      */
  13.     private int nr1;
  14.     /**
  15.      * Tickets nr2.
  16.      */
  17.     private int nr2;
  18.     /**
  19.      * Holds ticket nr.
  20.      */
  21.     private long ticketNr;
  22.  
  23.     /**
  24.      * Sets tickets data.
  25.      *
  26.      * @param nr1
  27.      *            - nr1.
  28.      * @param nr2
  29.      *            - nr2.
  30.      * @param ticketNr
  31.      *            - tickets serial number.
  32.      */
  33.     public LotteryTicket(int nr1, int nr2, long ticketNr) {
  34.         this.nr1 = nr1;
  35.         this.nr2 = nr2;
  36.         this.ticketNr = ticketNr;
  37.         System.out.println("Olete ostnud pileti numbritega: '" + nr1 + "' ja '"
  38.                 + nr2 + "'. Pileti kood on '" + this.ticketNr + "'");
  39.     }
  40.  
  41.     /**
  42.      * Checks if ticket has won or not.
  43.      *
  44.      * @param n1
  45.      *            - number 1.
  46.      * @param n2
  47.      *            - number 2.
  48.      * @return ture or false.
  49.      */
  50.     public boolean didIwin(int n1, int n2) {
  51.         if ((n1 == this.nr1 && n2 == this.nr2)
  52.                 || (n2 == this.nr1 && n1 == this.nr2)) {
  53.             return true;
  54.         }
  55.         return false;
  56.     }
  57.  
  58.     /**
  59.      * Returns ticket nr.
  60.      *
  61.      * @return tickets serial number.
  62.      */
  63.     public long getTicketNr() {
  64.         return this.ticketNr;
  65.     }
  66.  
  67.     /**
  68.      * Checks if ticket is valid.
  69.      * @return true or false.
  70.      */
  71.     public boolean isValid() {
  72.         return this.isValid;
  73.     }
  74.  
  75.     /**
  76.      * Toggles tickets validation.
  77.      */
  78.     public void toggleValid() {
  79.         this.isValid = false;
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement