//
//  movieApp.java
//  movieApp
//
//	builds on Movie.java
//
//  Created by Dan DeBlasio on 7/17/07.
//
import java.util.*;
import java.io.*;

public class movieApp {

    public static void main (String args[]) throws IOException {

		//prompt user for file
		Scanner cin = new Scanner(System.in);
		System.out.println("Filename:");
		String filename = cin.next();

		//open file and create scanner to read from it
		Scanner fin = new Scanner(new File(filename));

		//initialize the movie and the sequel,
		//apparently they both came out at the same time? w/e
		Movie movie = new Movie(fin.next(),fin.nextDouble());
		Movie sequel = movie.makeSequel();

		//gets the number of lines and loops thought the commands
		int j = fin.nextInt();
		for(int i=0;i<j;i++){
			int command = fin.nextInt();

			//sell tix to movie
			if(command == 1){
				int num = fin.nextInt();
				movie.sellTickets(num);
				System.out.printf("%s sold %d tickets and now has made $%.2f\n",movie.getTitle(), num, movie.getGrossRevenue());
			}

			//sell tix to sequel
			else if(command == 2){
				int num = fin.nextInt();
				sequel.sellTickets(num);
				System.out.printf("%s sold %d tickets and now has made $%.2f\n", sequel.getTitle(), num, sequel.getGrossRevenue());
			}

			//free to movie
			else if(command == 3){
				int num = fin.nextInt();
				movie.giveFreeTickets(num);
				System.out.println(movie.getTitle()+" gave away "+num+" tickets and now has had "+movie.getNumViewers()+" viewers");
			}

			//free to sequel
			else if(command == 4){
				int num = fin.nextInt();
				sequel.giveFreeTickets(num);
				System.out.println(sequel.getTitle()+" gave away "+num+" tickets and now has had "+sequel.getNumViewers()+" viewers");
			}

			//up price movie
			else if(command == 5){
				movie.upTicketPrice(fin.nextDouble());
				System.out.printf("%s raised its price to $%.2f\n", movie.getTitle(), movie.getTicketPrice());
			}

			//up price sequel
			else if(command == 6){
				sequel.upTicketPrice(fin.nextDouble());
				System.out.printf("%s raised its price to $%.2f\n", sequel.getTitle(), sequel.getTicketPrice());
			}

			//send movie to dollar
			else if(command == 7){
				movie.moveToDollarTheater();
				System.out.println(movie.getTitle()+" moved to the dollar theater");
			}

			//send sequel to dollar theater
			else if(command == 8){
				sequel.moveToDollarTheater();
				System.out.println(sequel.getTitle()+" moved to the dollar theater");
			}

			//exception case, if it gets here the command is not right
			else{
				System.out.println("Invalid Command on Line "+i+" of the input file '"+filename+"'");
			}

		}//for

		//summary output
		System.out.println("\n"+movie+"\n"+sequel);

		//big hit final output - movie
		System.out.print(movie.getTitle()+" was ");
		if(!movie.bigHit()) System.out.print("not "); // only print if not a big hit
		System.out.println("a big hit");

		//big hit final output - sequel
		System.out.print(sequel.getTitle()+" was ");
		if(!sequel.bigHit()) System.out.print("not ");//only print if not a big hit
		System.out.println("a big hit");

		//winner output
		if(movie.compareTo(sequel)>0){
			System.out.println(movie.getTitle()+" beat "+sequel.getTitle()+" at the box office");
		}else if(sequel.compareTo(movie)>0){
			System.out.println(sequel.getTitle()+" beat "+movie.getTitle()+" at the box office");
		}else{ // tie
			System.out.println(movie.getTitle()+" and "+sequel.getTitle()+" earned the same at the box office");
		}

    }//main

}//class
