Question

JAVA LinkedList/Queue - Implementation. New concert tickets are available. You have to enter the names of...

JAVA

LinkedList/Queue - Implementation.

New concert tickets are available. You have to enter the names of the people in order to form a line. However, you will later find out that a few people are not eligible to buy tickets because they represent scalpers instead of actual concert goers. You will have to remove those people from the line. A special raffle will be done and the result of the raffle will insert a person to the front of the line. You will have to issue tickets to the first 10 people in line, but there are 15 people total in line. The others will have to put into a waitlist queue for the next available ticket.

Program Implementation Requirements

Use the Linked List (Original Line) and a Queue (waitlist) concept to create this program. The class name will be ConcertTickets. You will have the following methods: insertIntoLine(Person p), removeFromLine(Person p), addToWaitList(Person p). Click here for the test-harnessPreview the document.

Test Harness:

import java.util.ArrayList;

public class ConcertTicketsTest {

public static void main(String[] args) {

ArrayList<String> listOfPeople = new ArrayList<String>();

listOfPeople.add("Monica");

listOfPeople.add("Chandler");

listOfPeople.add("Rachel");

listOfPeople.add("Phobe");

listOfPeople.add("Joey");

listOfPeople.add("Ross");

listOfPeople.add("John");

listOfPeople.add("Daenerys");

listOfPeople.add("Arya");

listOfPeople.add("Sansa");

listOfPeople.add("Rob");

listOfPeople.add("Ned");

listOfPeople.add("David");

listOfPeople.add("Trevor");

listOfPeople.add("Stephen");

ConcertTickets concertTickets = new ConcertTickets(listOfPeople);

concertTickets.removeFromLine("Ned");

concertTickets.removeFromLine("Ross");

concertTickets.insertIntoLine("Megatron");

concertTickets.insertInFront("Cersei");

System.out.println(concertTickets.printWaitlist());

System.out.println(concertTickets.listOfTicketHolders());

}

}

Homework Answers

Answer #1

ConcertTickets.java

import java.util.ArrayList;

public class ConcertTickets {
   // create array list
   private ArrayList<String> listOfPeople;
   // parameterized constructor
   public ConcertTickets(ArrayList<String> listOfPeople) {
       this.listOfPeople = listOfPeople;
   }
   // method to remove person from line
   public boolean removeFromLine(String name) {
       return listOfPeople.remove(name);
   }
   // method to insert person into line
   public void insertIntoLine(String name) {
       listOfPeople.add(name);
   }
   // method to insert person in front of the line
   public void insertInFront(String name) {
       listOfPeople.add(0, name);
   }
   // method to print the waiting list
   public void printWaitList() {
       System.out.println("\nWait list:");
       for(int i=10;i<15;i++)
           System.out.println(listOfPeople.get(i));
   }
   // method to print the ticket holders
   public void listOfTicketHolders() {
       System.out.println("\nTicket Holders:");
       for(int i=0;i<10;i++)
           System.out.println(listOfPeople.get(i));
   }
}

ConcertTicketsTest.java

import java.util.ArrayList;

public class ConcertTicketsTest {
   public static void main(String[] args) {
       // create array list of string type
       ArrayList<String> listOfPeople = new ArrayList<String>();
       // add 15 persons into list
       listOfPeople.add("Monica");
       listOfPeople.add("Chandler");
       listOfPeople.add("Rachel");
       listOfPeople.add("Phobe");
       listOfPeople.add("Joey");
       listOfPeople.add("Ross");
       listOfPeople.add("John");
       listOfPeople.add("Daenerys");
       listOfPeople.add("Arya");
       listOfPeople.add("Sansa");
       listOfPeople.add("Rob");
       listOfPeople.add("Ned");
       listOfPeople.add("David");
       listOfPeople.add("Trevor");
       listOfPeople.add("Stephen");
       // create object of ConcertTickets class
       ConcertTickets concertTickets = new ConcertTickets(listOfPeople);
       concertTickets.removeFromLine("Ned"); // remove Ned from line
       concertTickets.removeFromLine("Ross"); // remove Ross from line
       concertTickets.insertIntoLine("Megatron"); // insert Megatron into the line
       concertTickets.insertInFront("Cersei"); // insert Cersei in front of the line
       concertTickets.printWaitList(); // print wait list
       concertTickets.listOfTicketHolders(); // print the list of ticket holders
   }
}

Output

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Using JAVA For this assignment, you will analyze code that uses a file input stream and...
Using JAVA For this assignment, you will analyze code that uses a file input stream and a file output stream. Read through the linked Java™ code. In a Microsoft® Word document, answer the following questions: Could this program be run as is? If not, what is it lacking? Does this program modify the contents of an input stream? In what way? What are the results of running this code? ********************************************** CODE TO ANALYZE  ******************************************************** /********************************************************************** *   Program:   Datasort *   Purpose:   ...
Hi, I'm writing a Java program that prints a grid with circles and squares that have...
Hi, I'm writing a Java program that prints a grid with circles and squares that have letters in them and it is also supposed to print the toString() function to the console window each time the application runs. This toString() function is supposed to show the tile's shape, letter, and color component (or components). Could someone please review and debug my code to help me figure out why my toString() function is not working? import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton;...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT