Need help coming up with the code for this: /** IC: Arrays V2 - Due 11/23/15 Ins
ID: 3764880 • Letter: N
Question
Need help coming up with the code for this:
/** IC: Arrays V2 - Due 11/23/15
Instructions: Code a 2-dimensional (2D) array that stores the average scores for 2
football teams across 2 years. In a method called setAvgScores, prompt for the
averages and store them in the 2D array which will be returned. In the main(), call
setAvgScores() and print the averages. Save the program as ArraysV2.java.
Which one is the row and which one is the column? Hint: For every team there are 2 years of stats.
Prompt: This prompt will be repeated for each team where the single 9s in the label represent the
year and the team respectively.
Enter the average score for year 9 of football team 9:
Output:
Average Score for Football Team 9 - Year 9: ZZ9.99
Average Score for Football Team 9 - Year 9: ZZ9.99
***SAMPLE OUTPUT (INCLUDING PROMPTS)***
Enter the average score for year 1 of football team 1: 21.7
Enter the average score for year 2 of football team 1: 20
Enter the average score for year 1 of football team 2: 22
Enter the average score for year 2 of football team 2: 20.6
Average Score for Football Team 1 - Year 1: 21.70
Average Score for Football Team 1 - Year 2: 20.00
Average Score for Football Team 2 - Year 1: 22.00
Average Score for Football Team 2 - Year 2: 20.60
*/
import java.util.Scanner;
public class ArraysV2
{
public static void main(String[] args)
{
}//END main()
public static double setAvgScore()
{
}//End setAvgScore(): Static Double
}//END APPLICATION CLASS Demo2DArrays
Explanation / Answer
Here is the code for you. If you have any further queries, just get back to me.
import java.util.Scanner;
public class ArraysV2
{
public static void main(String[] args)
{
double[][] TeamScores = new double[2][2];
TeamScores = setAvgScore();
System.out.printf("Average Score for Football Team 1 - Year 1: %.2f ", TeamScores[0][0]);
System.out.printf("Average Score for Football Team 1 - Year 2: %.2f ", TeamScores[0][1]);
System.out.printf("Average Score for Football Team 2 - Year 1: %.2f ", TeamScores[1][0]);
System.out.printf("Average Score for Football Team 2 - Year 2: %.2f ", TeamScores[1][1]);
}//END main()
public static double[][] setAvgScore()
{
double[][] TeamScores = new double[2][2];
Scanner sc = new Scanner(System.in);
System.out.print("Enter the average score for year 1 of football team 1: ");
TeamScores[0][0] = sc.nextDouble();
System.out.print("Enter the average score for year 2 of football team 1: ");
TeamScores[0][1] = sc.nextDouble();
System.out.print("Enter the average score for year 1 of football team 2: ");
TeamScores[1][0] = sc.nextDouble();
System.out.print("Enter the average score for year 2 of football team 2: ");
TeamScores[1][1] = sc.nextDouble();
return TeamScores;
}//End setAvgScore(): Static Double
}//END APPLICATION CLASS Demo2DArrays
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.