Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Class ConcertTicket Need help on public ConcertTicket remove TODOS Please and thankyou! 3. Double-click to open the Wallet class, and examine the code. You will
Class ConcertTicket
Need help on public ConcertTicket remove TODOS
Please and thankyou!
3. Double-click to open the Wallet class, and examine the code. You will notice that the Wallet class includes an array called 'tickets' that holds Concert Tickets a complete method for expanding the array a complete method for adding tickets an incomplete method that removes a ConcertTicket from the wallet. 4. Your job is to make the incomplete method complete by filling statements that help remove the Concert Ticket at the end of the ticket list of the wallet and return the removed ticket. The method should be called remove. It should take no parameters, but it should return the most recently added ConcertTicket 1 Source History IC package Concert Ticket; 2 import java.util.Calendar; 3 import java.util.Arrays; 4 import java.util.Date; 5 6 /** 7 This class is a wallet which can store any number of concert tickets. 8 9 p000 10 public class Wallet { * Array of Concertticket objects 11 12 13 14 o 15 16 17 18 19 20 21 0 22 23 24 25 26 final static int INIT_CAPACITY = 10; protected ConcertTicket [] tickets = new ConcertTicket [10]; private int size = 0; Add a concert ticket into the array @param ct a concert ticket being added to the wallet public void add(ConcertTicket ct) { if (ct == null) return; 27 if (this.size == this.tickets.length) { this.resize(); ) this.tickets[this.size] = ct; this.size++; 28 29 30 31 32 33 34 35 36 37 38 39 40 41 0 42 } * Resizes the wallet so that you can fit more tickets. public void resize() { this.tickets = Arrays.copyof(this.tickets, 2 * this.tickets.length); S * Converts the wallet into a string representation for easy reading. * @return a string representation of the wallet */ @Override public String toString() { return Arrays.toString (Arrays.copyof(this.tickets, size)); } * Returns how many tickets are in the wallet. * @return the size of the wallet */ public int getSize() { return this.size; /** * Returns the size of the wallet. * @return the size of the wallet */ public int getLength() { return this.tickets.length; 1 Removes the most recently added concert ticket from the wallet * @return the concert ticket removed from the wallet public ConcertTicket remove() { // Create a ConcertTicket reference variable (DO NOT create a // new ConcertTicket - JUST create the reference variable) Concert Ticket ticket = null; if (this.size > 0) { // TODO Use the size variable // (which always points at the next empty // slot) to get the last added ConcertTicket from the array: // TODO Set that array slot to null: // TODO Decrement the size variable: } // Return the ConcertTicket: return ticket; } public static void main(String argv[]) { Wallet wallet = new Wallet(); Calendar cal = Calendar.getInstance(); cal.set(Calendar. YEAR, 2019); cal.set(Calendar.MONTH, Calendar. SEPTEMBER); cal.set (Calendar.DAY_OF_MONTH, 29); Date aDate = cal.getTime(); wallet.add(new ConcertTicket ("Titanic", aDate, 18.5)); wallet.add(new ConcertTicket ("The Matrix", aDate, 18.5)); wallet.remove(); System.out.println("Size of Wallet: " + wallet.getSize()); } } public class ConcertTicket implements Comparable { private String name; private Date date; private double price; /** Constructor with default value for all the fields. * @param name of band * @param date of the concert * @param price of the ticket */ public Concertticket (String name, Date date, double pri this.name = name; this.date = date; this.price = price; * Default constructor for this class. public Concertticket() { name = date = new Date(); price = 0.0; /** Getter returning the name of the band performing con * @return name of the band */ public String getName() { return name; } Setter storing the name of the band. * @param name to be stored for the band */ public void setName (String name) { this.name = name; 0 /** Getter returning the date of the concert. * @return the date of the concert */ public Date getDate() { return date; } /** * Setter storing the date of the concert. * @param date the date of the concer public void setDate (Date date) { this.date = date; * Getter returning the price for the ticket to the concert. * @return the price */ public double getPrice () { return price; } /** * Setter to set the price of the ticket of the concert. * @param price the price of the ticket */ public void setPrice (double price) { this.price = price; } /** * Method from comparable that compares two concert ticket objects by * looking at ticket price. * @param o * @return -1,0,1 */ @Override public int compareTo (Object o) { ConcertTicket ct = (ConcertTicket) o; int result = 0; // compare by price if (this.price ct.price) { result 1; } return result; } * Returns a string version of this object. * @return string representation of this object @Override public String toString() { return "ConcertTicket{" + "name=" + name + ", date= + date + ", price=" + price + 'i'; } }Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started