Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public class Lottery { private int [] ticket; public final int size = 8; public

ID: 3771977 • Letter: P

Question

public class Lottery {

      

    private int[] ticket;

    public final int size = 8;

   

   

    public void generateTicket()

    {

      /*

       * this method will generate random number in the range of 0 through 9     

       (0 and 9 included) for each element in the ticket array

      */

    }

    public Lottery()

    {

       ticket = new int[size];

       //call the method generateTicket() to initialize the ticket array

      

    }

   

    public int[] getTicket()

    {

     

      // return an exact but independent copy of ticket array

    }

   

    public void ToString()

    {

     //displays the ticket as an integer

    }

   public void setTicket(int[] newTicket)

    {

       size = newTicket.length;

       //copy the contents of newTicket in the instance variable ticket

      

    }

    public boolean MatchTicket(int[] ticketDrawn)

    {

       /*

       * compares the corresponding elements in ticketDrawn and ticket

       * returns true if all the corresponding elements match

       */

    }

}

public class Lottery {

      

    private int[] ticket;

    public final int size = 8;

   

   

    public void generateTicket()

    {

      /*

       * this method will generate random number in the range of 0 through 9     

       (0 and 9 included) for each element in the ticket array

      */

    }

    public Lottery()

    {

       ticket = new int[size];

       //call the method generateTicket() to initialize the ticket array

      

    }

   

    public int[] getTicket()

    {

     

      // return an exact but independent copy of ticket array

    }

   

    public void ToString()

    {

     //displays the ticket as an integer

    }

   public void setTicket(int[] newTicket)

    {

       size = newTicket.length;

       //copy the contents of newTicket in the instance variable ticket

      

    }

    public boolean MatchTicket(int[] ticketDrawn)

    {

       /*

       * compares the corresponding elements in ticketDrawn and ticket

       * returns true if all the corresponding elements match

       */

    }

}

Explanation / Answer

package assignment;

import java.util.Random;

public class LotteryTest {

   public static void main(String[] args) {
       Lottery lot = new Lottery();
      
       int ticket1[] = lot.getTicket();
       System.out.println(" User bought Ticket: ");
               lot.ToString();
      
       //Generate new ticket - which is prize winning ticket
       lot.generateTicket();
      
      
      
       System.out.println("Result: Matching: "+lot.MatchTicket(ticket1));
      
       //now match two ticket
               System.out.println(" Lottery - prize winning ticket: ");
               lot.ToString();
              
      
   }
  
}




class Lottery {

    

    private int[] ticket;

    public int size = 8;





    public void generateTicket()

    {

      
      /*

       * this method will generate random number in the range of 0 through 9   

       (0 and 9 included) for each element in the ticket array

      */

       Random rand = new Random();
       int max = 9;
       int min = 0;
       for(int i = 0; i < ticket.length; i++)
           ticket[i] = rand.nextInt((max - min) + 1) + min;

    }

    public Lottery()

    {

       ticket = new int[size];

       //call the method generateTicket() to initialize the ticket array
     
       generateTicket();    

    }



    public int[] getTicket()

    {

        // return an exact but independent copy of ticket array

       int ltickets[] = new int [this.ticket.length];
       for(int i = 0; i < ticket.length; i++)
           ltickets[i] = ticket[i];
       return ltickets;
   

    }



    public void ToString()

    {

     //displays the ticket as an integer
       String str = "";
       for(int i = 0; i < ticket.length; i++)
           str+= ""+(ticket[i]);
      
       System.out.println(str);

    }

   public void setTicket(int[] newTicket)

    {

       size = newTicket.length;

       //copy the contents of newTicket in the instance variable ticket
       ticket = new int[size];
       for(int i = 0; i < size; i++)
           ticket[i] = newTicket[i];
    

    }

    public boolean MatchTicket(int[] ticketDrawn)

    {

       /*

       * compares the corresponding elements in ticketDrawn and ticket

       * returns true if all the corresponding elements match

       */
      
       for(int i = 0; i < ticket.length; i++) {
           if(ticket[i] != ticketDrawn[i])
               return false;
       }
      
       return true;

    }

}


--output--

User bought Ticket:
24455616
Result: Matching: false
Lottery - prize winning ticket:
40274573