Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

implement two main classes: Player and PlayerDatabase to store the details of a set of players. You will also create another class called A PlayerDatabaseDemowhich

implement two main classes: Player and PlayerDatabase to store the details of a set of players. You will also create another class called A PlayerDatabaseDemowhich will contain the main method to test the two classes.

The PlayerClass: This class should simulate a player. The classs responsibilities are as follows:

To know the players name, score, and shirt number. ASSUME that the name of the player consists of only ONE WORD/String.

Instance variables: String Name, int Score, int Shirt

Required methods: one copy constructor, two constructors, accessors and mutators. The constructors are given below. The Default constructor is written for you. You need to complete the other two constructors.

public Player()

Name = ;

Score = 0;

Shirt = 0;

public Player(String newName, int newScore, int newShirt)

{

}

public Player(Player P)

{

}

The PlayerDatabase Class: The object of this class should store a list of up to 10 objects of the class Player. This class should have private Player[] playersand private int numPlayersas instance variables. The class should have only one constructor (given below)

public PlayerDatabase(int num)

{

numPlayers = num;// need to update this

//when you add, //remove players.

players = new Player[numPlayers];

}

This class should support the following methods (See below). You can add additional methods if you need to. Keep in mind; the maximum number of players is 10. In the methods, you need to make sure that the database doesnt allow the user to add exceed more than 10 players. To make things easier lets assume no two players have the same name. In any of the search methods, if the player couldnt be found, you should display that the player wasnt found in the database.

Add a new player to the PlayerDatabase through a series of inputs (from keyboard) from the user.

public void AddPlayer()

// not more than 10 players in the database allowed

Add a set of players to the PlayerDatabase through a file.

public void AddPlayer(String PlayersFile, int num)

{

//num is the number of players in the file.

numPlayers = num;

// not more than 10 players in the database allowed

}

The File PlayersFile contains several lines, where each line is of the format

PlayerName score shirtnumber

THIS method should always display the players information in descending orderof their scores.

public void DisplayPlayers()

{

}

Allow the user to enter a players name, this method finds the player with that specific name in the database and then displays that players name, score and shirt number. This method should give a not found message if the player wasnt found in the database.

public void SearchPlayersByName(String playerName)

{

}

Allow the user to enter a players shirt number, this method finds the player with that specific shirt number in the database and then displays that players name, score and shirt number. This method should give a not found message if the player wasnt found in the database.

public void SearchPlayersByshirt(int playerShirtNumber)

{

}

Allow the user to enter a players score, this method finds ALL THE players with that specific score in the database and then returns all the matching players. This method should give a message if no players were found.

public Player[] SearchPlayersByScore(int playerScore)

{

}

Allows the user to enter a players name and remove the player having that name from the database. This method should give an error message if no players were found.

public void RemovePlayerByName()

{

}

Prints the players name, score, and shirt number contained in PlayerDatabase

public void DisplayPlayers()

{

}

A PlayerDatabaseDemo Class to test the above two classes. This class will only have the main method. In the main method you will test the two classes Playerand PlayerDatabase

public class PlayerDatabaseDemo

{

publicstaticvoidmain(String[] args)

{

//Testing the copy constructor of Player

// Player p1 = new Player(Sam,20,1);

// Player p2 = new Player(p1);

// p1.setName(John);//setName() is a mutator method

// System.out.println(p1.getName() == p2.getName()); //should be false

//getName() is an accessor method

// PlayerDatabase Sim= new PlayerDatabase();

/*

Use AddPlayer(String PlayersFile) to load players

Display number of players in the database

3. You should display all the players in the database- their names,

scores and shirt numbers (one player per line)

4. Here you need to create a menu systemthat allows the user to select

which option or method to invoke from the Class PlayerDatabase. Provide an option to

allow the user to exit from the menu

5. After it exits from the menu system, display number of remaining

players in the database. Then, display all the remaining players -their

names, scores and shirt numbers in the database (one player per line)

*/

}

}

A Sample players File:

John 20 1

Walter 402

David 45 10

Sam 0 20

Little 0 22

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 Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions

Question

7. Where Do We Begin?

Answered: 1 week ago