This is supposed to read scores in a basketabll game. I can't seem to figure out why it won't read past the 4th quarter, it needs to read up until the 9th so basically from 5th-9th quarter should be considered OT. Also, how can I add the quarter label above the output score. Thanks in advance!
public static int REGULATION_NUM_QUARTERS = 4;
public static int MAX_BOX_SCORE_LENGTH = 9;
public static final int SENTINEL = -999;
private static final int AWAY = 1;
private static final int HOME = 2;
public static void initialize (int[] awayScores, int [] homeScores ) {
for (int i = 0; i < MAX_BOX_SCORE_LENGTH; i++ ){
awayScores [i] = SENTINEL;
}
for (int i = 0; i < MAX_BOX_SCORE_LENGTH; i++ ){
homeScores [i] = SENTINEL;
}
}
public static void readScores(Scanner scores, int[] awayScores, int[] homeScores) {
int team = AWAY;
int quarter = 1;
while (!gameIsOver(quarter, team, awayScores, homeScores)) {
if (team == AWAY) {
awayScores [quarter -1]= scores.nextInt();
team = HOME;
}
else {
homeScores [quarter-1]= scores.nextInt();
team = AWAY;
quarter++;
}
}
}
public static int gameScore(int[] teamBoxScore) {
int output = 0;
for (int i : teamBoxScore) {
if (i != SENTINEL) {
output += i;
}
}
return output;
}
public static int quarters(int[] teamBoxScore) {
int output = 0;
for (int i : teamBoxScore) {
if (i != SENTINEL) {
output++;
}
}
return output;
}
public static boolean gameIsOver(int quarter, int team, int[] awayScores, int[] homeScores) {
int awayScore = gameScore(awayScores);
int homeScore = gameScore(homeScores);
return (quarter > REGULATION_NUM_QUARTERS && team == AWAY && awayScore != homeScore)
|| (quarter == REGULATION_NUM_QUARTERS && team == HOME && awayScore < homeScore);
}
public static void printBoxScore(int[] awayScores, int[] homeScores) {
System.out.println();
System.out.print(" Away: ");
for (int v : awayScores) {
if (v != SENTINEL) {
System.out.print(v);
}
}
System.out.println();
System.out.print(" Home: ");
for (int v : homeScores) {
if (v != SENTINEL) {
System.out.print(v);
}
}
System.out.println();
}
public static int printBoxScore(int[] teamBoxScore) {
int i;
for (i = 0; i < teamBoxScore.length; i++) {
if (teamBoxScore[i] != SENTINEL) {
System.out.print(teamBoxScore[i] + " ");
} else
break;
}
System.out.println();
return i;
}
public static int printBoxScore(String name, int[] teamBoxScore) {
System.out.print(name);
return printBoxScore(teamBoxScore);
}
public static String result(int quarter, int awayScore, int homeScore) {
if (awayScore > homeScore) {
return "The away team won "
+ awayScore + " to " + homeScore
+ " in REGULATION";
}
if (homeScore > awayScore ) {
return "The home team won "
+ homeScore + " to " + awayScore
+ " in REGULATION";
}
return "";
}
public static String result(int[] awayScores, int[] homeScores) {
int awayScore = gameScore(awayScores);
int homeScore = gameScore(homeScores);
int quarter = printBoxScore(" Away : ", awayScores);
printBoxScore(" Home: ", homeScores);
return result(quarter, awayScore, homeScore);
}
public static void main(String[] args) {
int[] awayScores = new int [MAX_BOX_SCORE_LENGTH];
int[] homeScores = new int [MAX_BOX_SCORE_LENGTH];
initialize (awayScores, homeScores);
Scanner input = new Scanner(System.in);
System.out.print("Do you want to see BoxScore? (y or n): ");
String answer = input.next();
System.out.println("Please enter the scores below");
readScores(input, awayScores, homeScores);
if (answer.charAt(0) == 'y' || answer.charAt(0) == 'Y') {
System.out.println(result(awayScores, homeScores));
}
else {
System.out.println(result(quarters(awayScores), gameScore(awayScores), gameScore(homeScores)));
}
}
}
[Edit: pre tags]