public static void main(String[] args) {
		
		//Creates a buy queue and a sell queue for orders.
		PriorityQueue<Bid> sellQueue = new PriorityQueue<Bid>();
		PriorityQueue<Bid> buyQueue = new PriorityQueue<Bid>(Collections.reverseOrder());
		
		//Creates an array to hold orders that are parsed, but not added to a PQ yet.
		ArrayList<Bid> incomingOrders = new ArrayList<Bid>(); 
		String[] rawInput;
		
		//Temporary variables for parsing info.
		int cost;
		int quantity;
		//Parses in the given orders from raw input
		 
			// Adds the raw input to an array of strings to be parsed.
			rawInput = StdIn.readAllLines();
			String delimiters = "[ ]+";
		
			System.out.println("");
			System.out.println("Note: invalid entries will be ignored.");
			System.out.print("On input: ");
		
			// Parses each line into a bid.
			for(int i = 0; i < rawInput.length; i++){
				String[] tokens = rawInput[i].split(delimiters);
			
				if(tokens.length == 3){
					// Stores cost and quantity variables for the line.
					cost = Integer.parseInt(tokens[1]);
					quantity = Integer.parseInt(tokens[2]);
				
					// Determines whether to create a buy or sell bid.
					if(tokens[0].equals("buy")){
						Buy newBuyOrder = new Buy(cost, quantity);
						incomingOrders.add(newBuyOrder);
					
						//Prints output for a single order.
						if(firstValue){
							System.out.print("(Buy, " + cost + ", " + quantity + ")");
							firstValue = false;
						}
						else{
							System.out.print(", (Buy, " + cost + ", " + quantity + ")");
						}
					}
					else if(tokens[0].equals("sell")){
						Sell newSellOrder = new Sell(cost, quantity);
						incomingOrders.add(newSellOrder);
					
						//Prints output for a single order.
						if(firstValue){
							System.out.print("(Sell, " + cost + ", " + quantity + ")");
							firstValue = false; // Sets to false.
						}
						else{
							System.out.print(", (Sell, " + cost + ", " + quantity + ")");
						}
					}
				
			}
			
		}
		
		System.out.println(""); // Creates a newline for program clarity.
		System.out.print("The sequence of sales is: [");
		
        
		firstValue = true; // Sets to true again to maintain correct output formatting while running make_trades.
        boolean notFinished = true; //Used to determine whether to continue the while loop below.
        /* Checks whether the market is in equilibrium: if the Market is in equilibrium and there are no
         * incoming orders that have not been added to the market, there are no more transactions. 
         * Otherwise, the market will complete the needed transactions to reach equilibrium. */
        while(notFinished){
        	if(MarketEquilibrium(sellQueue, buyQueue)){
        		if(incomingOrders.isEmpty()){
        			notFinished = false; //Ends while loop.
        		}
        		else{ //Adds an incoming order from the incoming list.
        			Bid tempBid = incomingOrders.get(0); //Saves first order to a temporary variable.
        			incomingOrders.remove(0); //Removes the first order from the incoming orders list.
        			if (tempBid instanceof Sell) {
        				sellQueue.add(tempBid);
        			}
        			else if(tempBid instanceof Buy){
        				buyQueue.add(tempBid);
        			}
        		}
        	}
        	else{
        		make_trades(sellQueue, buyQueue);
        		
        	}
        }
        System.out.print("]");
        
        // goes through remaining orders that could not be completed
        System.out.println(""); //Newline
        System.out.println("");
        System.out.println("The market is in equilibrium!");
        System.out.println("");
        firstValue = true;
        
        System.out.println("Here are the remaining buy orders:");      
        System.out.print("[");
        while(!buyQueue.isEmpty()) {
        	Bid b = buyQueue.poll();
        	
        	if(firstValue){
        		System.out.print("(Buy, "+ b.cost +", "+ b.quantity + ")");
        		firstValue = false;
        	}
        	else{
        		System.out.print(", (Buy, "+ b.cost +", "+ b.quantity + ")");
        	}
        	
        }
        System.out.print("]"); //End of buy orders and formatting.
        System.out.println("");
        
        firstValue = true;
        System.out.println("Here are the remaining sell orders:");
        System.out.print("[");
        while(!sellQueue.isEmpty()) {
        	Bid s = sellQueue.poll();
        	
        	if(firstValue){
        		System.out.print("(Sell, "+ s.cost +", "+ s.quantity + ")");
        	}
        	else{
        		System.out.print(", (Sell, "+ s.cost +", "+ s.quantity + ")");
        	}
        	
        }
        System.out.print("]"); //End of sell orders.
        
        
}