Starting CodeSolutionimport javautilScanner class FantasyFoo
Starting Code
Solution
import java.util.Scanner;
class FantasyFootball
{
private int numberOfTeams; // Same as teamAverage.length.
private int numberOfWeeks; // Same as weekAverage.length.
private int[][] scores; //numberOfTeams rows and numberOfWeeks columns.
private double[] weekAverage; // contains an entry for each week
private double[] teamAverage; // contains an entry for each team
private String[] teamName; // contains an entry for each team
public void enterInData( )
{
Scanner keyboard = new Scanner(System.in);
System.out.println(\"Enter number of teams:\");
numberOfTeams = keyboard.nextInt( );
System.out.println(\"Enter number of weeks:\");
numberOfWeeks = keyboard.nextInt( );
//String teamName[]=new String[numberOfTeams];
//int scores[][]=new int[numberOfTeams][numberOfWeeks];
// ************** Fill in Code ***************
// Allocate array memory for teamName to store the team names.
// Allocate array memory for scores (2 dimensional array) to store a
// score for each team for each week.
for (int team = 0; team < numberOfTeams; team++)
{
System.out.println(\"Enter team name\");
// ************* Fill in Code **************
// Read in Team name and store it in teamName
String name=keyboard.nextLine();
teamName[team]=name;
for (int week = 0; week < numberOfWeeks; week++)
{
System.out.println(\"Enter score for team \"+ teamName[team]);
System.out.println(\"on week number \" + (week+1));
// ************ Fill in Code ***************
// Read in a score and store it in the proper spot in the scores array
int score=keyboard.nextInt();
scores[team][week]=score;
}
}
}
public void fillTeamAverage( )
{
//********* Fill in Code *************
// Allocate memory for the teamAverage.
// Each entry in this array will contain the
// average weekly score for a given team.
//double teamAverage[]=new double[numberOfTeams];
for (int team = 0; team < numberOfTeams; team++)
{
int sum=0;
double average=0.0;
for (int week = 0; week < numberOfWeeks; week++)
{
sum=sum + scores[team][week];
}
average=sum/numberOfWeeks;
teamAverage[team]=average;
}
}
public void fillWeekAverage( )
{
//*********** Fill in Code *************
// Allocate memory for the weekAverage instance variable.
// Each entry in this array will contain the average of
// all teams for a given week.
//double weekAverage[]=new double[numberOfTeams];
for (int week = 0; week < numberOfWeeks; week++)
{
int sum=0;
double average=0.0;
for (int team = 0; team < numberOfTeams; team++)
{
sum=sum + scores[team][week];
}
average=sum/numberOfTeams;
weekAverage[numberOfWeeks]=average;
}
}
public void display( )
{
//********* Fill in Code ****************
// This method will print out the display that was shown above.
// At this point all of the information can be found in the
// private instance variables of the FantasyFootball class
System.out.print(\"Team Name\");
System.out.print(\'\\t\');
int i=0,j=0;
while(i<numberOfWeeks)
{
System.out.print(\"Team\"+(i+1));
System.out.print(\'\\t\');
i++;
}
System.out.println();
i=0;
while(i<numberOfTeams){
System.out.print(teamName[i]);
System.out.print(\'\\t\');
j=0;
while(j<numberOfWeeks)
{
System.out.print(scores[i][j]);
System.out.print(\'\\t\');
j++;
}
System.out.print(\"avg=\"+(int)teamAverage[i]);
System.out.println();
i++;
}
j=0;
System.out.print(\"Weekly Avg\");
System.out.print(\'\\t\');
while(j<numberOfWeeks)
{
System.out.print((int)weekAverage[j]);
System.out.print(\'\\t\');
j++;
}
}
public static void main(String[] args)
{
FantasyFootball f= new FantasyFootball();
f.enterInData();
f.fillTeamAverage();
f.fillWeekAverage();
f.display();
}
}


