Answered step by step
Verified Expert Solution
Link Copied!

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 2019
*/
public class Wallet {
/**
* Array of ConcertTicket objects
*/
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 (this.size == this.tickets.length){
this.resize();
}
this.tickets[this.size]= ct;
this.size++;
}
/**
* Resizes the wallet so that you can fit more tickets.
*
*/
public void resize(){
this.tickets = Arrays.copyOf(this.tickets, 2* 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.toString(Arrays.copyOf(this.tickets, 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 0;
}
/**
* 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 (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:
}
// TODO: Return the ConcertTicket:
return null;
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions