Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA: I will PayPal you 40$ if you meet all test requirements. Question: HELP NEEDED! I need the code template at the bottom to be

JAVA: I will PayPal you 40$ if you meet all test requirements.

Question: HELP NEEDED! I need the code template at the bottom to be edit to meet the following test criteria

HELP NEEDED!

I need the code template at the bottom to be edited to meet the following test criteria!

Problem Summary This program will store roster for a soccer team. Coaches rate players to ensure a balanced team. Each player has a jersey number (0 - 99) and a rating (1 - 9). The roster is stored in a data file. Each line of the file stores data for one player (jersey number and rating). Test Data Files

r2.txt 8 7 55 9

r5.txt 8 7 55 9 14 8 22 6 34 8

r12.txt

11 1 22 2 33 3 44 4 55 5 66 6 77 7 88 8 99 9 12 5 23 6 32 7

The program will read the roster data from the specified data file, and store the data into an array of objects. The program will then allow the user to modify the roster, via a menu of choices (display, add, update, save, and exit), until the user chooses to exit. This project contains 3 classes: ? The RosterManager class contains the main() method (outline code provided). ? The Player class has data fields and methods for the players jersey number and rating (complete code provided). ? The PlayerArrayImpl class has data fields and methods for an array of Player objects and a count of the number of players (outline code provided). Each step of the instructions is associated with specific tests, so you can test your program as you go along. Test 1 (15 pts) Implement the method to read the data file and store data in the array. Within the PlayerArrayImpl class, in the readRosterFile() method: ? Define File and Scanner variables ? Open the file specified in the parameter for reading ? Loop: o Read the jersey number and the rating from one data line o Create a new Player object, using the data read as the arguments for the constructor o Store the object in the playerArray o Increment the count until all data has been read from the file ? Close the file NOTES o Exceptions will not be handled inside this method. They will be thrown to the calling method. o Your code should not check to see if the array is full this error will be handled by the calling method when the system automatically throws an ArrayIndexOutOfBoundsException if there is too much data in the file.

Tests 2 & 3 (10 pts) Try to read the data from the data file and catch any IOExceptions Within the RosterManager class, in the main() method: ? Within a try block: o Use the roster object to call the readRosterFile() method o Use the roster object and a getter to display the number of players data stored 5 players stored ? Within a catch block for an IOException: o Display the following error messages, including the filename: **Error reading input file filename.txt **Program exiting o Exit the program with: System.exit(99); Test 4 (5 pts) Create a method to display a menu and read a choice from the user Within the RosterManager class, below the main() method, create a new public static method that: ? Has one parameter a Scanner to read input from the keyboard ? Displays a blank line, and then the following menu of options for a user to modify the roster: MENU D - Display Roster A - Add a Player U - Update a Player's Rating S - Save Roster E - Exit program Enter choice: ? Reads and returns the users uppercased choice character Test 5 - 6 & Test 16 (20 pts) Add code to process menu choice and recognize invalid entries Implement the "Display Roster" menu option Within the PlayerArrayImpl class, in the displayRoster() method: ? Add the code to display all the roster data stored in the playerArray, formatted as follows: Player 1 - jersey #8, rating is 7 Player 2 - jersey #55, rating is 9 Within the RosterManager class, in the main() method, ? Loop to: o Call the menu method and save the returned choice o Execute a switch statement with a case for each choice ? For choice D, use the roster object to call the displayRoster() method ? For all other choices, just break from the switch statement ? Include a default clause which displays the message: Error -- invalid menu choice until the user enters E to exit

Tests 7 & 8 (10 pts) Implement the "Add a player" menu option Within the PlayerArrayImpl class, in the addPlayer() method: ? If the playerArray is full, display the message: Roster is full -- cannot add more players ? Otherwise: o Create a new Player object, using the parameters as arguments to the constructor o Store the new Player object in the playerArray and increment the count o Display the following message that includes the jersey number: Player 55 successfully added Within the RosterManager class, in the main() method, ? For choice A: o Prompt for and read a jersey number and rating o Use the roster object to call the addPlayer() method with the jersey number and rating as arguments Tests 9 11 (15 pts) Implement the "Update a players rating" menu option Within the PlayerArrayImpl class, in the updatePlayerRating() method: ? Search the playerArray for the player with the jersey number specified in the first parameter (Hint: use a getter to access the jersey number within each Player object) ? If the jersey number is found o Update that player's rating using the value from the second parameter (Hint: Use a setter to change the rating within the object) ? Otherwise: o Display the error message Jersey number 33 not found -- cannot update rating Within the RosterManager class, in the main() method, ? For choice U: o Prompt for and read a jersey number and a new rating o Use the roster object to call the updatePlayerRating() method with the jersey number and rating as arguments Tests 12 & 13 (15 pts) Implement the "Save roster" menu option Within the PlayerArrayImpl class, in the writeRosterFile() method: ? Within a try block: o Define File and PrintWriter variables o Open the file specified in the parameter for writing o For each Player object in the playerArray: ? Write the jersey number and the rating to one line of the file, separated by a space (Hint: Use getters to access the data fields of the Player object) o Close the file

o Display the following confirmation message including the filename: Roster saved to file filenameV2.txt ? Within a catch block for IOExceptions: o Display the following error message including the filename: **Error: cannot create new roster file filenameV2.txt Within the RosterManager class, in the main() method, ? For choice U: o Use some String methods to create a new filename, starting with the input data filename ? Extract the characters before the .txt ? Append V2.txt onto the extracted characters Example: For input file data.txt, output file will be dataV2.txt o Use the roster object to call the writeRosterFile() method, using the new filename as an argument to the method. Test 14 & 15 (10 pts) Implement check if file has too many lines of data (and check different length filename for saving) Within the RosterManager class, in the main() method: ? For the try block that calls the readRosterFile() method, after the catch block for an IOException, add a second catch block for an ArrayIndexOutOfBoundsException o Display the following error messages: **Too many players in file **Program will only use the first X players where X is the ROSTER_MAX value (Player.java and PlayerArrayImpl and RosterManager.java) SAMPLE RUN Enter input data filename: r2.txt 2 players stored MENU D - Display Roster A - Add a Player U - Update a Player's Rating S - Save Roster E - Exit program Enter choice: d Player 1 - jersey #8, rating is 7 Player 2 - jersey #55, rating is 9

MENU D - Display Roster A - Add a Player U - Update a Player's Rating S - Save Roster E - Exit program Enter choice: a Enter jersey number of player to add: 12 Enter rating of player: 8 Player 12 successfully added MENU D - Display Roster A - Add a Player U - Update a Player's Rating S - Save Roster E - Exit program Enter choice: u Enter jersey number of player to update: 8 Enter new rating of player: 6 MENU D - Display Roster A - Add a Player U - Update a Player's Rating S - Save Roster E - Exit program Enter choice: d Player 1 - jersey #8, rating is 6 Player 2 - jersey #55, rating is 9 Player 3 - jersey #12, rating is 8 MENU D - Display Roster A - Add a Player U - Update a Player's Rating S - Save Roster E - Exit program Enter choice: s Roster saved to file r2v2.txt MENU D - Display Roster A - Add a Player U - Update a Player's Rating S - Save Roster E - Exit program Enter choice: x Error -- invalid menu choice MENU D - Display Roster A - Add a Player U - Update a Player's Rating S - Save Roster E - Exit program Enter choice: e

/**

* Program to manage a soccer team roster of up to 11 players

* Roster data will be read from a file and stored

* User will be able to display the roster, add a player,

* update a player rating, and re-save the roster data.

*

* @author

*/

import java.io.IOException;

import java.util.Scanner;

public class RosterManager {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

Scanner keyboard = new Scanner(System.in);

PlayerArrayImpl roster = new PlayerArrayImpl();

String inputFilename;

System.out.println("Enter input data filename:");

inputFilename = keyboard.next();

}

/**

* Method displays menu to user

* Reads, uppercases, and returns choice from menu

*

* @param keyboard - Scanner to read user data from

* @return choice - uppercased menu choice entered by user

*/

public static char getChoice(Scanner keyboard) {

char choice = '?';

return choice;

}

}

/**

* Class Player defines data and method members for Player class objects

* which represent soccer players on a team

*/

public class Player {

private int jerseyNum;

private int rating;

/**

* default constructor

*/

public Player() {

jerseyNum = 0;

rating = 0;

}

/**

* constructor with parameters

*

* @param jerseyNum

* @param rating

*/

public Player(int jerseyNum, int rating) {

this.jerseyNum = jerseyNum;

this.rating = rating;

}

/**

* getter

*

* @return rating

*/

public int getRating() {

return rating;

}

/**

* setter

*

* @param rating

*/

public void setRating(int rating) {

this.rating = rating;

}

/**

* getter

*

* @return jerseyNum

*/

public int getJerseyNum() {

return jerseyNum;

}

/**

* setter

*

* @param jerseyNum

*/

public void setJerseyNum(int jerseyNum) {

this.jerseyNum = jerseyNum;

}

}

/**

* Class to define data fields and methods for an array of Players

* which represents a roster for a soccer team

* @author

*/

import java.io.File;

import java.io.IOException;

import java.io.PrintWriter;

import java.util.Scanner;

public class PlayerArrayImpl {

public final static int ROSTER_MAX = 11; // size of array

private Player [] playerArray; // list of players

private int numPlayers; // number of players in list

/**

* Constructor

*/

public PlayerArrayImpl() {

this.numPlayers = 0;

playerArray = new Player[ROSTER_MAX];

}

/**

* getter

* @return numPlayers

*/

public int getNumPlayers() {

return numPlayers;

}

/**

* setter

* @param numPlayers

*/

public void setNumPlayers(int numPlayers) {

this.numPlayers = numPlayers;

}

/**

* Method to read player data from file specified by filename

* Each line of the file will contain a player number and a player rating,

* separated by a space. Sample file lines:

* 45 8

* 33 6

* The method will create a player object from each line of data,

* and place the object into the playerArray

*

* @param filename - name of file containing player data

* @throws IOException - to be handled by caller

*/

public void readRosterFile(String filename) throws IOException,

ArrayIndexOutOfBoundsException {

}

/**

* Method to display player jersey numbers and player ratings

* for each player in playerArray

*/

public void displayRoster() {

}

/**

* Method to add a player to the playerArray, if there is room

*

* @param jerseyNum - of player to add

* @param rating - of player to add

*/

public void addPlayer(int jerseyNum, int rating) {

}

/**

* Method to update one player's rating

* @param jerseyNum - of player to update

* @param rating - player's new rating

*/

public void updatePlayerRating(int jerseyNum, int rating) {

}

/**

* Method to save the data from playerArray to a file

* (IOExceptions handled within the method)

* Each line of the file will contain a player number and a player rating,

* separated by a space. Sample file lines:

* 45 8

* 33 6

*

* @param filename - name of file to write data to

*/

public void writeRosterFile(String filename) {

}

/**

* getter - FOR TESTING USE ONLY -- STUDENTS SHOULD NOT CALL THIS METHOD IN THEIR PROGRAMS

* @return array of players

*/

public Player[] getPlayerArray() {

return playerArray;

}

}

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

Step: 3

blur-text-image

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

Data Visualization A Practical Introduction

Authors: Kieran Healy

1st Edition

0691181624, 978-0691181622

More Books

Students also viewed these Databases questions

Question

(f) What type of factorial design it is? Pg45

Answered: 1 week ago

Question

Describe the Indian constitution and political system.

Answered: 1 week ago

Question

Explain in detail the developing and developed economy of India

Answered: 1 week ago

Question

Problem: Evaluate the integral: I = X 52+7 - 1)(x+2) dx

Answered: 1 week ago

Question

What is gravity?

Answered: 1 week ago

Question

What is the Big Bang Theory?

Answered: 1 week ago