The basic idea of this assignment is to create a program that can provide a summary and identify who won a "match" in a sports event (football, basketball, Soccer, baseball, etc.)
**This is my code:**
`import java.util.Scanner;
public class Team {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Ask questions about the game type etc.
System.out.println("Please enter game name: ");
String gameName = sc.next();
System.out.println("Please enter " + gameName + " team 1 name: ");
String t1N = sc.next();
System.out.println("Please enter " + gameName + " team 2 name: ");
String t2N = sc.next();
System.out.println("What is a score in " + gameName + " called? ");
String scoreName = sc.next();
System.out.println("How many points per " + scoreName + " in " + gameName + "?");
int scoreValue = sc.nextInt();
System.out.println("What is a period in " + gameName + " called?");
String periodName = sc.next();
System.out.println("How many " + periodName + " in " + gameName + "?");
int numberOfPeriods = sc.nextInt();
int sum1 = 0;
int sum2 = 0;
for (int i = 1; i <= numberOfPeriods; i++) {
System.out.println(periodName + " #" + i);
System.out.println("How many " + scoreName + " for " + t1N + "?");
int numberOfScoresT1[] = new int[sc.nextInt()];
System.out.println("How many " + scoreName + " for " + t2N + "?");
int numberOfScoresT2[] = new int[sc.nextInt()];
for (int counter = 0; counter < numberOfScoresT1.length; counter++)
sum1 += numberOfScoresT1[counter];
for (int counter = 0; counter < numberOfScoresT1.length; counter++)
sum2 += numberOfScoresT2[counter];
}
System.out.println("Team 1 scored " + sum1 + " team 2 scored " + sum2);
}`
This is the error I'm receiving: Please enter game name: Football Please enter Football team 1 name: Dolphins Please enter Football team 2 name: Jaguars What is a score in Fotball called? Touchdown How many points per Touchdown in Fotball? 7 What is a period in Fotball called? Quarter How many Quarter in Fotball? 4 Quarter #1 How many Touchdown for Dolphins? 3 How many Touchdown for Jaguars? 2 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 at Team.main(Team.java:36)
I recognize that the arrays I'm using are in the for loop, and I think thats what is causing the problem, but i'm not sure how to fix it.
This is a sample output is supposed to look like: Quarter #1: How many Touchdowns for Dolphins? 2 How many Touchdowns for Chargers? 1
Quarter #2: How many Touchdowns for Dolphins? 0 How many Touchdowns for Chargers? 1
Quarter #3: How many Touchdowns for Dolphins? 0 How many Touchdowns for Chargers? 2
Quarter #4: How many Touchdowns for Dolphins? 3 How many Touchdowns for Chargers? 0
Football Game Results:
Dolphins scored 5 Touchdowns for a score of 35 Chargers scored 4 Touchdowns for a score of 28
Dolphins Win by 7 points!