Answered step by step
Verified Expert Solution
Question
1 Approved Answer
package ConcertTicket; import java.util.Arrays; / * * * This class iallet which can store any number of concert tickets. * * @version Fall 2 0
package ConcertTicket;
import java.util.Arrays;
This class iallet which can store any number of concert tickets.
@version Fall
public class Wallet
Array of ConcertTicket objects
protected ConcertTicket tickets new ConcertTicket;
private int size ;
Add a concert ticket into the array
@param ct a concert ticket being added to the wallet
public void addConcertTicket ct
if thissize this.tickets.length
this.resize;
this.ticketsthissize ct;
this.size;
Resizes the wallet so that you can fit more tickets.
public void resize
this.tickets Arrays.copyOfthistickets, this.tickets.length;
Converts the wallet into a string representation for easy reading.
@return a string representation of the wallet
@Override
public String toString
return Arrays.toStringArrayscopyOfthistickets, size;
Returns how many tickets are in the wallet.
@return the size of the wallet
public int getSize
TODO: Implement getSize
getSize;
return this.size;
Returns the size of the wallet.
@return the size of the wallet
public int getLength
TODO: Implement getLength
getLength;
return ;
Removes the most recently added concert ticket from the wallet
@return the concert ticket removed from the wallet
public ConcertTicket remove
TODO: Create a ConcertTicket reference variable DO NOT create a
new ConcertTicket JUST create the reference variable
new ConcertTicket;
if thissize
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:
TODO: Return the ConcertTicket:
return null;
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