/*********************************************************************
 * Author: B. Alex Bridges                                           *
 * File: Bowling.java                                                *
 * Class: CPSC-101 Lab Section 3                                     *
 * Project: Lab 7 - Bowling Score Keeper                             *
 * Purpose: This program keeps score for a single person in bowling. *
  *********************************************************************/

/* IMPORTS */
import java.awt.*;
import java.io.*;


class Bowling
{
	/*********************************************************************
	 * MAIN METHOD                                                       *
	 *********************************************************************/
	/*************************************************************************
	 * Purpose: Keeps score for a single person in bowling.                  *
	 * Input: STANDARD = For 10 frames, the number of pins dropped per ball  *
	 * Output: STANDARD = For 10 frames, the number of pins dropped per      *
	 *                      ball and the current score                       *
	 * Called Routines: N/A                                                  *
	 * Assumptions: N/A                                                      *
	 *************************************************************************/
	public static void main (String[] args) throws IOException
	{
		/* LOCAL VARIABLES */
		int int_i = 1;					// CURRENT LOOP COUNT/ARRAY INDEX FOR BALL 1 & BALL 2
		int intA_Ball1[] = new int[13];	// NUMBER OF PINS DROPPED FOR BALL 1
		int intA_Ball2[] = new int[13];	// NUMBER OF PINS DROPPED FOR BALL 2
		int intA_Scores[] = {0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};// THE SCORE PER FRAME
		int int_Strikes = 0;			// CURRENT NUMBER OF STRIKES
		boolean b_Spare = false;		// SPARE FLAG
		int int_n = 1;					// ARRAY INDEX FOR SCORES
			
		/* STANDARD TEXT INPUT STREAM SETUP */
		BufferedReader stdin = new BufferedReader( new InputStreamReader(System.in) );

		/* HEADER */
		System.out.println("B. Alex Bridges");
		System.out.println("CPSC-101, Winter 1998");
		System.out.println("The Bowling Score Keeper Program");
		System.out.println(); // BLANK LINE
		
		/* IGNORE INPUT'S 1st LINE COMMENT */
		stdin.readLine();
		
		/* FRAMES 1 - 10 */
		for (int_i = 1; int_i <= 12 ; int_i++)
		{		
			/* BALL 1 */
			// INPUT
			intA_Ball1[int_i] = Integer.parseInt( stdin.readLine() );
			
			// OUTPUT
			if (int_i < 11)
				System.out.println("Frame "+int_i+"'s 1st Ball: "+intA_Ball1[int_i]);
			else
			{
				System.out.println("Frame 10's Bonus Ball: "+intA_Ball1[int_i]);
			} //else
			
			// ERROR CHECKING
			if(intA_Ball1[int_i] > 10)
				System.out.println("ERROR: The max. score per frame of 10 has been exceeded!");

			// STRIKE --> INCREMENT COUNT
			if(intA_Ball1[int_i] == 10)
				int_Strikes++;
										
			// CALCULATING SCORES
			// => 2 STRIKES PREVIOUSLY
			if(int_Strikes == 2)
			{
				int_Strikes--;
				if(int_i > 2)
				{
					intA_Scores[int_i - 2] = (intA_Scores[int_i - 3] + 30);
				} // if
			} // if
			// => SPARE PREVIOUSLY
			else if(b_Spare == true)
			{
					intA_Scores[int_i - 1] = (intA_Scores[int_i - 2] + 10 + intA_Ball1[int_i]);
					b_Spare = false;
			} // if
			
			// THE SCORES PER FRAME
			System.out.print("Scores: ");
			while(int_n <= int_i)
			{
				if(intA_Scores[int_n] != -1)
					System.out.print(intA_Scores[int_n]+"  ");
				int_n++;
			} // while
			int_n = 1; // RESET ARRAY INDEX FOR SCORES
			System.out.println(); // CARRIAGE RETURN
			System.out.println(); // BLANK LINE	
	
			// BALL 2
			if(intA_Ball1[int_i] != 10)
			{
				// INPUT
				intA_Ball2[int_i] = Integer.parseInt( stdin.readLine() );

				// OUTPUT
				if (int_i != 11)
					System.out.println("Frame "+int_i+"'s 2nd Ball: "+intA_Ball2[int_i]);
				else
					System.out.println("Frame 10's Bonus Ball: "+intA_Ball2[int_i]);

				// ERROR CHECKING
				if( (intA_Ball1[int_i] + intA_Ball2[int_i]) > 10 )
					System.out.println("ERROR: The max. score per frame of 10 has been exceeded!");

				// SPARE --> SET FLAG
				if( (intA_Ball1[int_i] + intA_Ball2[int_i]) == 10 )
					b_Spare = true;
					
				// CALCULATING SCORES
				// => 1 STRIKE PREVIOUSLY
				if(int_Strikes == 1)
				{
					intA_Scores[int_i - 1] = (intA_Scores[int_i - 2] + 10 + intA_Ball1[int_i] + intA_Ball2[int_i]);
					int_Strikes--;
				} // if
				// => NORMAL - FRAME 1 (SPECIAL CASE)
				else if( ( (intA_Ball1[int_i] + intA_Ball2[int_i]) != 10) && (int_i == 1) )
					intA_Scores[int_i] = (intA_Ball1[int_i] + intA_Ball2[int_i]);
				// => NORMAL - ALL OTHER FRAMES
				else
					intA_Scores[int_i] = (intA_Scores[int_i - 1] + intA_Ball1[int_i] + intA_Ball2[int_i]);
				
				// THE SCORES PER FRAME
				System.out.print("Scores: ");
				while(int_n <= int_i)
				{
					if(intA_Scores[int_n] != -1)
						System.out.print(intA_Scores[int_n]+"  ");
					int_n++;
				} // while
				int_n = 1; // RESET ARRAY INDEX FOR SCORES
				System.out.println(); // CARRIAGE RETURN
				System.out.println(); // BLANK LINE	
			} // if
		} //for				
	} //method main
} //class Bowling

