question archive For this assignment you are given the following files: Assignment08

For this assignment you are given the following files: Assignment08

Subject:Computer SciencePrice: Bought3

For this assignment you are given the following files:

Assignment08.java (make no changes to this file) added to the bottom of the questions

Roster1.dat (make no changes to this file) added to the bottom of the questions

Roster2.dat (make no changes to this file) added to the bottom of the questions

Player.java (you must completee this file) added to the bottom of the questions

Roster.java (you must completee this file) added to the bottom of the questions

 

Problem Description and Given Info

 

The volleyball coach at Verde Valley High School would like some help managing her team. She would like a program to help her identify the best players. She has team rosters stored in text files that contain the names of her players (first name, then last name separated by a space), and their stats as attacks per set (a double) followed by blocks per set (a double). Higher stats are better. Each data field is separated by a space. For example, one line in a roster file would look like:

Gabrielle Reece 4.57 1.79

 

The coach would like the program to do the following:

 

Present a menu with the following options:

 

1. Open a roster file

2. List all players

3. List top attackers

4. List top blockers

5. Add a player

6. Change a player's stats

7. Count players

8. Quit program

 

When the user chooses 1 to open a roster file, then the program will ask for the filename of a roster file, then open and read the data from that file into an ArrayList.

 

When the user chooses 2 to list all players, then the program will list the names and stats of all player players.

 

When the user chooses 3 to list top attackers, then the program will determine and list the names and stats of the players with the top 2 attack stats.

 

When the user chooses 4 to list top blockers, then the program will determine and list the names and stats of the players with the top 2 stats for blocks.

 

When the user chooses 5 to add a player, then the program will prompt the user to enter the new player's name (first and last), attack stat (double), and block stat (double). The program should collect this information from the user, and then instantiate a new Player object with the given name and stats, and add that Player to the roster.

 

When the user chooses 6 to change a player's stats, then the program will prompt the user to enter the player's name (first and last). If there is a player on the roster with the given name, then the program will collect the new attack stat (double), and block stat (double), and will update the stat values for this player.

 

When the user chooses 7 to count players, then the program will display the number of players on the current roster.

 

When the user chooses 8 the program will end.

 

The main class has already been designed and written for this program (given in Assignment08.java). Carefully review the code in the Assignment08.java file and be sure that you understand how it works.

 

Your task is to implement the Player and Roster classes. The Player class will allow us to instantiate Player objects that will store the important information (name, attack stat, block stat) for a player. The Roster class will allow us to createe and manage a roster of players - we will use an ArrayList to store the Player objects.

 

Part 1 - Implement the Player Class

 

In a file named Player.java, implement the class described below.

 

The Player class must have the following private instance variables: ?

 

a variable named name that will store a String ?

a variable named attackStat that will store a double ?

a variable named blockStat that will store a double

 

The Player class must have the following public constructor method: ?

an overloaded constructor that takes three arguments. The first argument will be a String (player's name). The second (attack stat) and third (block stat) arguments will be double.

 

The Player class must have the following public methods: ?

a method named getName. This accessor method will take no arguments. This method will return a String. ?

a method named getAttackStat. This accessor method will take no arguments. This method will return a double. ?

a method named setAttackStat. This mutator method will take one double argument. This method will not return anything. ?

a method named getBlockStat. This accessor method will take no arguments. This method will return a double. ?

a method named setBlockStat. This mutator method will take one double argument. This method will not return anything. ?

a method named printPlayerInfo. This method will take no arguments. This method will not return anything.

 

Other Details ?

The overloaded constructor should initialize the object's name, attackStat and blockStat variables with the values passed in to the parameter variables. ?

The getName accessor method should simply return the value stored in the object's name variable. ?

The getAttackStat accessor method should simply return the value currently stored in the object's attackStat variable. ?

The setAttackStat mutator method should store the value passed in as an argument in the object's attackStat variable. ?

The getBlockStat accessor method should simply return the value currently stored in the object's blockStat variable. ?

The setBlockStat mutator method should store the value passed in as an argument in the object's blockStat variable. ?

The printPlayerInfo method should print out to the console, the name and stats for this player object. The printout should look like this:

 

Rachael Adams (attack = 3.36, block = 1.93)

 

Part 2 - Implement the Roster Class

In a file named Roster.java, implement the class described below.

The Roster class must have the following private instance variables: ?

a variable named players that will store a reference to an ArrayList

 

The Roster class must have the following public constructor methods: ?

a default constructor ?

an overloaded constructor that takes one argument. This argument will be a String.

 

The Roster class must have the following public methods: ?

a method named addPlayer. This method will take three arguments. The first argument will be a String (player's name). The second (attack stat) and third (block stat) arguments will be double. ?

a method named countPlayers. This method will take no arguments. This method will return an int. ?

a method named getPlayerByName. This method will take one String argument. This method will return a Player reference. ?

a method named printTopAttackers. This method will take no arguments. This method will not return anything. ?

a method named printTopBlockers. This method will take no arguments. This method will not return anything. ?

a method named printAllPlayers. This method will take no arguments. This method will not return anything.

 

Other Details

The default constructor should instantiate a new ArrayList object, and store a reference to this object in the Roster's players instance variable.

The overloaded constructor should instantiate a new ArrayList object, and store a reference to this object in the Roster's players instance variable. It should then open the open the roster file named in the parameter variable. It should then read in the data from this roster file and, for each line in the file, it should createe a new Player object with the player name and stat data on that line, and add this Player to the ArrayList players.

 

The addPlayer method should instantiate a new Player object with the name and stats provided in the argument values, and then add this Player to the roster's ArrayList object.

 

The countPlayers method should return the number of players currently stored in the roster's ArrayList object. The getPlayerByName method should iterate through the roster's ArrayList object and search for a player with a name that is equal to the argument value. If such a Player is found, then this method should return a reference to that Player object, otherwise this method should return null.

 

The printTopAttackers method should determine the two Player objects with the best attack stats (in descending order). It should then call the printPlayerInfo method on these Player objects.

The printTopBlockers method should determine the two Player objects with the best block stats (in descending order). It should then call the printPlayerInfo method on these Player objects.

The printAllPlayers method should iterate through the roster's ArrayList object and call the printPlayerInfo method on each of these Player objects.

 

 

 

 

 

// !!! Make no changes to this .java file !!!

import java.io.*;

import java.util.Scanner;

 

class Assignment08 {

 static Scanner scnr = new Scanner(System.in);

 

 public static void main(String[] args) throws IOException {

  Roster roster = new Roster();

 

  int menuChoice = 0;

 

  while (menuChoice != 8) {

   displayMenu();

   menuChoice = getMenuChoice();

 

   if   (menuChoice == 1)

    roster = openRosterFile();

   else if (menuChoice == 2)

    listAllPlayers(roster);

   else if (menuChoice == 3)

    listTopAttackers(roster);

   else if (menuChoice == 4)

    listTopBlockers(roster);

   else if (menuChoice == 5)

    addPlayer(roster);

   else if (menuChoice == 6)

    changePlayerStats(roster);

   else if (menuChoice == 7)

    countPlayers(roster);

   else if (menuChoice == 8)

    System.out.println("===== Quitting Program =====");

   else

    System.out.println(" !!! Invalid Menu Choice !!!");

  }

 }

 

 static void displayMenu() {

  System.out.println("===== Menu =====");

  System.out.println("1. Open a roster file");

  System.out.println("2. List all players");

  System.out.println("3. List top attackers");

  System.out.println("4. List top blockers");

  System.out.println("5. Add a player");

  System.out.println("6. Change a player's stats");

  System.out.println("7. Count players");

  System.out.println("8. Quit program");

 }

 

 static int getMenuChoice() {

  System.out.print("Enter your menu Choice --> ");

  return scnr.nextInt();

 }

 

 static Roster openRosterFile() throws IOException {

  System.out.print("Enter roster file name --> ");

  String fileName = scnr.next();

 

  return new Roster(fileName);

 }

 

 static void listAllPlayers(Roster roster) {

  System.out.println("===== All Players =====");

  roster.printAllPlayers();

 }

 

 static void listTopAttackers(Roster roster) {

  System.out.println("===== Top Attackers =====");

  roster.printTopAttackers();

 }

 

 static void listTopBlockers(Roster roster) {

  System.out.println("===== Top Blockers =====");

  roster.printTopBlockers();

 }

 

 static void addPlayer(Roster roster) {

  String fullName = getPlayerName();

  double attackStat = getAttackStat();

  double blockStat = getBlockStat();

 

  roster.addPlayer(fullName, attackStat, blockStat);

 }

 

 static void changePlayerStats(Roster roster) {

  String fullName = getPlayerName();

 

  Player playerToUpdate = roster.getPlayerByName(fullName);

 

  if (playerToUpdate != null) {

   double newAttackStat = getAttackStat();

   double newBlockStat = getBlockStat();

 

   playerToUpdate.setAttackStat(newAttackStat);

   playerToUpdate.setBlockStat(newBlockStat);

  } else {

   System.out.printf(" !!! No player with the name %s found !!!n", fullName);

  }

 }

 

 static void countPlayers(Roster roster) {

  System.out.printf("There are %d players on this roster.n", roster.countPlayers());

 }

 

 static String getPlayerName() {

  System.out.print("Enter new player first name --> ");

  String firstName = scnr.next();

  System.out.print("Enter new player last name  --> ");

  String lastName = scnr.next();

   

  return firstName + " " + lastName;

 }

 

 static double getAttackStat() {

  System.out.print("Enter player's new attack stat --> ");

  return scnr.nextDouble();

 }

 

 static double getBlockStat() {

  System.out.print("Enter player's new block stat --> ");

  return scnr.nextDouble();

 }

}

 

 

 

 

 

 

 

 

 

// CSE 110   : <Class #> / <meeting days and times>

// Assignment : <assignment #>

// Author   : <name> & <studentID>

// Description : <Player>

 

 

 

 

 

 

 

// CSE 110   : <Class #> / <meeting days and times>

// Assignment : <assignment #>

// Author   : <name> & <studentID>

// Description : <ROSTER>

 

 

 

 

 

 

 

 

Roster1

Rachael Adams 3.36 1.93

 

Foluke Akinradewo 4.81 1.14

 

Kayla Banwarth 2.98 0.50

 

Michelle Bartsch 0.28 1.42

 

Krista Vansant 2.78 0.86

 

Courtney Thompson 0.59 0.93

 

Kelly Murphy 1.15 0.58

 

Lauren Gibbemeyer 2.25 0.50

 

Alexis Crimes 3.89 1.34

 

Tori Dixon 0.92 1.62

 

Nicole Fawcett 4.01 0.61

 

Alisha Glass 1.96 1.55

 

Natalie Hagglund 2.49 0.52

 

Kim Hill 1.53 1.76

 

Cursty Jackson 0.69 1.44

 

 

 

 

 

 

Roster 2

Ann Adams 1.0 4.4

 

Bob Barns 2.0 3.3

 

Carl Chad 3.0 2.2

 

Dani Davis 4.0 1.1

 

 

 

 

 

 

 

 

EXAMPLE Input & Output (bold is user input)

 

===== Menu =====

1. Open a roster file

2. List all players

3. List top attackers

4. List top blockers

5. Add a player

6. Change a player's stats

7. Count players

8. Quit program

Enter your menu Choice --> 1

Enter roster file name --> Roster2.dat

===== Menu =====

1. Open a roster file

2. List all players

3. List top attackers

4. List top blockers

5. Add a player

6. Change a player's stats

7. Count players

8. Quit program

Enter your menu Choice --> 5

Enter new player first name --> Yuli

Enter new player last name --> Deng

Enter player's new attack stat --> 5

Enter player's new block stat --> 5

===== Menu =====

1. Open a roster file

2. List all players

3. List top attackers

4. List top blockers

5. Add a player

6. Change a player's stats

7. Count players

8. Quit program

Enter your menu Choice --> 2

===== All Players =====

Ann Adams (attack = 1.00, block = 4.40)

Bob Barns (attack = 2.00, block = 3.30)

Carl Chad (attack = 3.00, block = 2.20)

Dani Davis (attack = 4.00, block = 1.10)

Yuli Deng (attack = 5.00, block = 5.00)

===== Menu =====

1. Open a roster file

2. List all players

3. List top attackers

4. List top blockers

5. Add a player

6. Change a player's stats

7. Count players

8. Quit program

Enter your menu Choice --> 6

Enter new player first name --> Yuli

Enter new player last name --> Deng

Enter player's new attack stat --> 6

Enter player's new block stat --> 6

===== Menu =====

1. Open a roster file

2. List all players

3. List top attackers

4. List top blockers

5. Add a player

6. Change a player's stats

7. Count players

8. Quit program

Enter your menu Choice --> 3

===== Top Attackers =====

Yuli Deng (attack = 6.00, block = 6.00)

Dani Davis (attack = 4.00, block = 1.10)

===== Menu =====

1. Open a roster file

2. List all players

3. List top attackers

4. List top blockers

5. Add a player

6. Change a player's stats

7. Count players

8. Quit program

Enter your menu Choice --> 4

===== Top Blockers =====

Yuli Deng (attack = 6.00, block = 6.00)

Ann Adams (attack = 1.00, block = 4.40)

===== Menu =====

1. Open a roster file

2. List all players

3. List top attackers

4. List top blockers

5. Add a player

6. Change a player's stats

7. Count players

8. Quit program

Enter your menu Choice --> 7

There are 5 players on this roster.

===== Menu =====

1. Open a roster file

2. List all players

3. List top attackers

4. List top blockers

5. Add a player

6. Change a player's stats

7. Count players

8. Quit program

Enter your menu Choice --> 8

===== Quitting Program =====

 

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Related Questions