Question: Skeleton: This code is a sample test for the question. You will need to add more tests to test all methods /* TicketManager tm =

Skeleton:
This code is a sample test for the question. You will need to add more tests to test all methods
/*
TicketManager tm = new TicketManager();
System.out.println(tm);
Ticket t1 = new Ticket((int)(Math.random()*5),(int)(Math.random()*5));
tm.buy(t1);
System.out.println(tm);
Ticket t2 = new Ticket((int)(Math.random()*5),(int)(Math.random()*5));
tm.buy(t2);
System.out.println(tm);
for(int j = 0; j
tm.buy(new Ticket((int)(Math.random()*5),(int)(Math.random()*5)));
}
System.out.println(tm.sold());
Ticket draw = new Ticket((int)(Math.random()*5),(int)(Math.random()*5));
System.out.println(tm.freqWinner(draw));
*/
}
}
/*
* Class: Ticket
*
* DO NOT EDIT!
*/
class Ticket{
private final int a,b;
Ticket(int a1, int b1){
a = a1; b = b1;
}
public int a(){
return a;
}
public int b(){
return b;
}
public String toString(){
return "["+a+","+b+"]";
}
}
* Class: TicketManager
* Please uncomment and fill in the 5 methods below
class TicketManager{
private Ticket[] tickets;
private int sold = 0;
private int maxTickets = 500;
TicketManager(){
}
//public boolean buy(Ticket t){
// Add the ticket to the next available slot in the list
//}
//public boolean buy(){
// Generate and add the ticket to the next available slot in the list
//}
//public int freqWinner(Ticket t){
// Count how many tickets match the winning ticket drawn
//}
//public Winner[] getWinners(Ticket t){
// Return a list of all tickets that match the winning ticket drawn
// Do not break encapsulation!
//}
//public boolean search(Ticket t){
// return true if a matching ticket is in the list
//}
//public int sold(){
// The number of tickets sold
//}
//public boolean allsold(){
// Return true if all tickets have been sold
//}
public String toString(){
if(sold == 0)
return "[]";
String s = "[";
for(int j = 0; j
s = s + tickets[j] + ",";
}
return s+tickets[sold-1]+"]";
}
}
A local lottery sells a small number of tickets for a draw Each ticket has only two numbers selected at random Numbers are restricted to values in the range 0..5. The class Ticket that encapsulates an individual ticket is given. A class TicketManager is also given and its methods are listed in the table below. Your task is to complete the methods listed. The toString method is given and should not be modified by you. Method TicketManagerO Semantics Constructor that creates an array of size maxTickets public boolean buy(Ticket t) Adds a ticket to the draw on condition that the number sold does not exceed maxTickets. It returns true if successful, false otherwise public boolean buy( Adds a ticket to the draw on condition that the number sold does not exceed maxTickets. It returns true if successful false otherwise. It shouod randomly select the numbers and generate the ticket (it's a quickpick) public int freqWinner(Ticket t) It checks for the number of winning tickets public boolean search(Ticket t) Searches for the given ticket and returns public int soldO after a draw takes place true if found; false otherwise. Returns the number of tickets sold Returns true if all tickets sold; false public boolean allsold() otherwise
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
