Write the Ticket class in this order: a static variable that counts the tickets sold, a variable for each ticket's own number, the constructor, then getNumber(). The first ticket made is number 1, the next is number 2, and so on.
For the third ticket made, getNumber() returns 3.
12 strips: R1 to R12
} R1} R2public class Ticket { R3private int number; R4} R5private int sold = 0; R6private static int sold = 0; R7return number; R8public int getNumber() { R9public Ticket() { R10number = sold; R11sold++; R12Order: R3, R7, R4, R10, R12, R11, R1, R9, R8, R2, R5. Extra: R6
Lines with the same mark can go in either order.
public class Ticket {
private static int sold = 0;
private int number;
public Ticket() {
sold++;
number = sold;
}
public int getNumber() {
return number;
}
} Extra strip: private int sold = 0;. Without static, every ticket gets its own sold variable, which starts at 0, so every ticket is number 1.