Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a FantasyFootball.java class to read in the information in the above table. One of the differences in the overall structure is the fact that

Create a FantasyFootball.java class to read in the information in the above table. One of the differences in the overall structure is the fact that in Gradebook we didn't have any Student names. In Fantasy Football we want a name for each team. This will require adding an additional array to store the names of the teams. You will simplify your efforts if the names of your teams do not include spaces. Then you can use next() instead of nextLine() and your code will be simplified. You will get most of the credit for this assignment even if your output is not completely aligned as shown in the above image. Note that if you use the technique from GradeBook.java you will get a ragged looking table. Getting the table aligned as seen in the above image will give you the last 5 points on this problem. You can get the alignment to look somewhat OK, if you use tab characters to go to new columns and round the double values to integer values with a cast operation. However, you can get perfect alignment using the System.printf(....) approach we have shown before. Consider the following examples of printf and println: String s ="something"; double d = 5.4321; int x = 3456; System.out.printf("%20s", s); //Field of 20 characters, right justified string System.out.printf("%-20s", s); //Field of 20 characters, left justified string System.out.printf("%8d", x); //Field of 8 characters, right justified integer System.out.prinf("%-8d", x); //Field of 8 characters, left justified integer System.out.println(); // Go to a new line You should start with the "Starting Code" shown below. Starting Code package fantasy_football; import java.util.Scanner; public 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( ); // ************** 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 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 } } } 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. } 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. } 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 } public static void main(String[] args) { FantasyFootball f= new FantasyFootball(); f.enterInData(); f.fillTeamAverage(); f.fillWeekAverage(); f.display(); } } ************************************ Sample Output from your program: Enter number of teams: 4 Enter number of weeks: 3 Enter team name Blind_Pigeons Enter score for team Blind_Pigeons on week number 1 123 Enter score for team Blind_Pigeons on week number 2 95 Enter score for team Blind_Pigeons on week number 3 121 Enter team name Spittn_Lamas Enter score for team Spittn_Lamas on week number 1 54 Enter score for team Spittn_Lamas on week number 2 98 Enter score for team Spittn_Lamas on week number 3 83 Enter team name Nut_Zippers Enter score for team Nut_Zippers on week number 1 70 Enter score for team Nut_Zippers on week number 2 74 Enter score for team Nut_Zippers on week number 3 103 Enter team name Bucking_Broncos Enter score for team Bucking_Broncos on week number 1 108 Enter score for team Bucking_Broncos on week number 2 119 Enter score for team Bucking_Broncos on week number 3 81 ******************************** output from display() with ragged output ******************************** Blind_Pigeons 123 95 121 Ave = 113 Spittn_Lamas 54 98 83 Ave = 78 Nut_Zippers 70 74 103 Ave = 82 Bucking_Broncos 108 119 81 Ave = 102 Weekly Ave: 88 96 97 ******************************** output from display() using printf ******************************** Team Name Week 1 Week 2 Week 3 Blind_Pigeons 123 95 121 ave = 113 Spittn_Lamas 54 98 83 ave = 78 Nut_Zippers 70 74 103 ave = 82 Bucking_Broncos 108 119 81 ave = 102 Weekly Ave: 88 96 97

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions

Question

12. Explain the concept of an Entity Relational Diagram.

Answered: 1 week ago

Question

Prepare an ID card of the continent Antarctica?

Answered: 1 week ago

Question

What do you understand by Mendeleev's periodic table

Answered: 1 week ago