Concert Wait List – Java

Concert Wait List – Java

The concert ticket object manages a list of concert goers up to a cap (decided by the user), the remaining are put onto a waiting list. Included methods can add and/or remove specific users from the list to a specific index of the user array.

ConcertTicketsTest.java

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());
	}

}

ConcertTickets.java

import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;

public class ConcertTickets {
	
	private Deque<String> concertList;
	private Deque<String> waitList;
	
	public ConcertTickets(ArrayList<String> listOfPeople) {
		
		this.concertList = new LinkedList<String>();
		this.waitList = new LinkedList<String>();
		
		for(String s: listOfPeople) {
			
			if(concertList.size() < 10) {
				concertList.add(s);
			}
			else {
				waitList.add(s);
			}
		}
	}
	
	public void insertIntoLine(String s) {
		
		if(concertList.size() <10) {
			concertList.add(s);
		}
		else {
			waitList.add(s);
		}
		
	}
	
	public void removeFromLine(String s) {
		
		if(concertList.contains(s)) {
			concertList.remove(s);
		}
		
		if(waitList.contains(s)) {
			waitList.remove(s);
		}
	}
	
	public void insertInFront(String s) {
		
		concertList.addFirst(s);
		if(concertList.size() < 10) {
			waitList.addFirst(concertList.removeLast());
		}
	}
	
	public Deque<String> printWaitlist() {
		return waitList;
	}
	
	public Deque<String> listOfTicketHolders() {
		return concertList;
	}

}

Leave a Reply