Question
****Below is my java eclipse coding that allows the user to record the scores for each team for each quarter of a football game. It
****Below is my java eclipse coding that allows the user to record the scores for each team for each quarter of a football game. It works great except I want the outputs of the final game scores of each quarter in perfectly aligned columns. If the 1st team name is longer or shorter than the 2nd team name, the first column of the first quarter scores are not perfectly aligned. The 2nd, 3rd, and 4th columns/ quarters are perfectly aligned.****
import java.util.Scanner;
public class FootballScore {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
String team[] = new String[20];
int points[][] = new int[5][5];
for (int i = 1; i <= 2; i++) {
System.out.print("Enter the name of team " + i + ": ");
team[i] = keyboard.next();
}
for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= 2; j++) {
System.out.print("Enter the points from quarter " + i + " for the " + team[j] + ": ");
points[i][j] = keyboard.nextInt();
}
}
outputResults(team, points);
}
public static void outputResults(String[] team, int[][] points) {
int total[] = new int[5];
System.out.println(" Game Summary");
System.out.println("------------");
for (int j = 1; j <= 2; j++) {
System.out.print(" " + team[j] + ": ");
for (int i = 1; i <= 4; i++) {
System.out.print(points[i][j] + "\t");
total[j] += points[i][j];
}
}
System.out.println("");
for (int j = 1; j <= 2; j++) {
System.out.print(" " + team[j] + ": " + total[j]);
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started