Question: Good Day. I do need help with this Java Programming. I am only posting the part I need help with. Copy TeamTest.java from Assignment 3

Good Day.

I do need help with this Java Programming.

I am only posting the part I need help with.

Copy TeamTest.java from Assignment 3 into cs520.hw4 and change its package name accordingly. Make the

following changes:

  • Remove the totalScoringAverage variable.

  • Modify the createPlayer() method:

o Make it return Player instead of double.

o Remove the lines of code that reference scoringAverage. o Return the new player instance at the end of the method.

In the main() method: o Create an ArrayList at the beginning of the method called players that will contain Player objects, i.e.new ArrayList().

o Read the lines from team.txt using Scanner and a loop just as in the previous assignment. o Within each iteration of the loop that reads the lines from team.txt:

Based on the changes you made to createPlayer() above, the method now returns a Player object rather than a double, so assign the returned Player object into a local variable called player and discard any references to totalScoringAverage.

Add player to the players list. o When all lines have been read from the file, your players variable should now be an ArrayList of 10Player object instances.

o Declare a String[ ] array called opponents and populate it with the name of any 5 opposing teams orschools. For example:

String[] opponents = new String[] {"BC", "Northeastern", "Harvard", "MIT", "UMass"};

o Loop through all members of the opponents array. In each loop iteration:

Create a new instance of Game (instantiated with no arguments) in a local variable of typeGame called game.

  • Call game.setTeamName(), passing whatever you want to call your team.

  • Call game.setOpponentName(), passing the opponent name (the current loop value).

  • Call game.setDate(), passing whatever date values you wish (it's OK to pass the same datevalues each time through the loop).

  • Call game.setPlayers(), passing the players ArrayList. The players will always be the same forall 5 Game objects you are creating.

  • Call game.simulateGame(). This will produce the output you added in that method.

o Retain the user-friendly exception handling.

I just need to know how to do this part.

Below is the code for TeamTest.java from my previous assignment if you need it to work with

package cs520.hw3.part2;

import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner;

public class TeamTest { public static double createPlayer(String number, String name, String pos, String year) {

int num = Integer.parseInt(number); Player player = new Player(name); player.setNumber(num); player.setPosition(pos); player.setYear(year); double average = player.computeScoringAverage(); System.out.println(player + " : " + average); return average; }

public static void main(String[] args) {

double totalScoringAverage = 0; int counter = 0; String file = "/Users/sophiaaligbe/Desktop/Eclipse.app/Player.java/src/cs520/hw3/part2/team.txt"; try { Scanner scanner = new Scanner(new File(file)); String num, name, pos, year; while (scanner.hasNextLine()) { counter++; num = scanner.nextLine(); name = scanner.nextLine(); pos = scanner.nextLine(); year = scanner.nextLine(); totalScoringAverage += createPlayer(num, name, pos, year); scanner.nextLine(); } scanner.close(); if (counter != 0) System.out.println("Average score: " + totalScoringAverage / counter);

} catch (FileNotFoundException e) { System.out.println("error: could not find file: " + file); return;

Good Day what do you mean by code in the comment session. can you explain

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!