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

. University of Harda W ork Raffle Objective: Review Jana by working uit h iff y

ID: 3854298 • Letter: #

Question


. University of Harda W ork Raffle Objective: Review Jana by working uit h iff ya, daises, and Deseriptisn The University of Hard w ork is sponsoring a raffle to raise money for the unisersty. of the raffle tickets has a unique sis diga number. The raffle comittee needs a computer application to analyze the results of the ratfle, determining the winning tickets The winning tickets are determined as follows Each The sx digit mumber on the ticket exactly mmat ches the winning number First Prize Example. f the rurter on the ticket is 123456, it i5 a winner if the mng number is 123456. + Second Prize Ther of the &digit; number on the ticken actly tches the wiming Esample: . r the number on the ticket is 654321, it is a winner if the wining number is t23456. * Third Prze Ay3 sequtial digta of ta 6 digt numbar on th tcket xly mates 3 sequential digit 2 in the EampleIf the number on the ticket is 123456, it is a winer if the iming number has 123 in postions 1-3, 234 in positions 2-4, 345 in positions 3 posituh of the wiring ticket 5, or 456 in positiona 4-6 1nstructions driver 4menda55) 5as programmer-defined dass mst be used The main program (driwer) should ask the user to eter the wining 6 digit nunber Do this only once Iput from the keyboard the ticket holder's name and his/her sx digit ticket number. Amalyze the ticket tù2ae if it is a nimer using the rules for "ining above. If the ticket i wnter, display a meaaage indicat ing the prize won and the holder'sa.Cont inua to proceas tcketsumil thare are n whenal ticket, hrve been processed. daylay the tota! nurrber of first prize wnnersecond prTre a, and third priza . The class ust be named Ticket. The ma n program [driver) must be amed Raffie. driver {main dassj well a53 programmer-defned dass must be LEed submt program through the agnment tool in Moodle2 1ndudes comment stating your name " · Ech student mnher own indapandent pr r a

Explanation / Answer

Below is your code: -

Ticket.java

public class Ticket {

private String ticketNo;

private String name;

public Ticket() {

}

public Ticket(String ticketNo, String name) {

this.ticketNo = ticketNo;

this.name = name;

}

public String getTicketNo() {

return ticketNo;

}

public void setTicketNo(String ticketNo) {

this.ticketNo = ticketNo;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

}

Raffle.java

import java.util.Scanner;

public class Raffle {

public static void main(String[] args) {

int firstwinners = 0, secondwinners = 0, thirdwinners = 0;

System.out.println(" Welcome to the Raffle Game ... !! ");

System.out.print(" Please enter the winning ticket number: ");

Scanner sc = new Scanner(System.in);

String winTickNo = sc.next();

boolean done = false;

String name, ticketNo;

Ticket tic;

while (!done) {

System.out.print(" Enter the name of holder: ");

name = sc.next();

System.out.print("Enter 6 digit ticket number: ");

ticketNo = sc.next();

tic = new Ticket(ticketNo, name);

if (tic.getTicketNo().equals(winTickNo)) {

firstwinners++;

System.out.println(tic.getName() + " has won first prize.");

} else if (new StringBuffer(tic.getTicketNo()).reverse().toString().equals(winTickNo)) {

secondwinners++;

System.out.println(tic.getName() + " has won second prize.");

} else if (tic.getTicketNo().substring(0, 3).equals(winTickNo.substring(0, 3))

|| tic.getTicketNo().substring(1, 4).equals(winTickNo.substring(1, 4))

|| tic.getTicketNo().substring(2, 5).equals(winTickNo.substring(2, 5))

|| tic.getTicketNo().substring(3, 6).equals(winTickNo.substring(3, 6))) {

thirdwinners++;

System.out.println(tic.getName() + " has won third prize.");

}

System.out.print(" Do you have more tickets to check: (y/n): ");

String op = sc.next();

if(!op.equals("y") && !op.equals("Y")) {

done = true;

}

}

System.out.println(" Total number of first prize winners: "+firstwinners);

System.out.println("Total number of second prize winners: "+secondwinners);

System.out.println("Total number of third prize winners: "+thirdwinners);

sc.close();

}

}

Sample run: -

Welcome to the Raffle Game ... !!

Please enter the winning ticket number: 123456

Enter the name of holder: sal
Enter 6 digit ticket number: 123456
sal has won first prize.

Do you have more tickets to check: (y/n): y

Enter the name of holder: ili
Enter 6 digit ticket number: 654321
ili has won second prize.

Do you have more tickets to check: (y/n): y

Enter the name of holder: ban
Enter 6 digit ticket number: 123789
ban has won third prize.

Do you have more tickets to check: (y/n): y

Enter the name of holder: sal
Enter 6 digit ticket number: 456987

Do you have more tickets to check: (y/n): y

Enter the name of holder: sasa
Enter 6 digit ticket number: 823456
sasa has won third prize.

Do you have more tickets to check: (y/n): n


Total number of first prize winners: 1
Total number of second prize winners: 1
Total number of third prize winners: 2

Let me know if you need anything else in this in comments