Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Although there is a lot of text, but this question is really simple, hope to get help. I give the class 1234 java code and

Although there is a lot of text, but this question is really simple, hope to get help.

I give the class 1234 java code and a part of class5 plaease have me to complete the class 5 javacode

image text in transcribedimage text in transcribedimage text in transcribed

Class1 Manager

package tennis;

public class Manager {

private String name;

public Manager(String name) { this.name = name; }

public String getName() { return (name); }

public String toString() { return ("Manager[ Name: " + name + " ]"); }

}

Class 2

package tennis;

public class Player {

private String name; private int age; private String countryCode;

public Player(String name, int age, String countryCode) { this.name = name; this.age = age; this.countryCode = countryCode; }

public String getName() { return (name); }

public int getAge() { return (age); }

public String getCountryCode() { return (countryCode); }

public String toString() { String desc = "Player[ name: " + name + ", age: " + age + ", country code: " + countryCode + " ]";

return desc; } }

Class3 Team

package tennis;

public class Team {

private String teamName; private static int totalNumOfTeams = 0; private Manager manager; private Player player;

public Team(String teamName, Player player) { this.teamName = teamName; this.player = player; this.manager = null; totalNumOfTeams++; }

public String getTeamName() { return teamName; }

public static int getTotalNumOfTeams() { return totalNumOfTeams; }

public Player getPlayer() { return (player); }

public Manager getManager() { if (manager != null) { return (manager); } else { return (null); } }

public boolean hasManager() { if (manager == null) { return (false); } else { return (true); } }

public void setManager(Manager manager) { if (this.manager == null) { this.manager = manager; } else { System.out.println("This team already has a manager."); } }

public String toString() { String description = "Team[ name: " + teamName + ", player: " + player.toString() + ", manager: ";

if (manager != null) { description += manager.toString(); } else { description += "No Manager "; }

description += "]"; return (description); }

}

Class4

package tennis; public class Tournament { private String tournamentID; private double prize; private Team[] teams; private int numTeamsRegistered; private final int MAX_TEAMS_REGISTERED = 8; public Tournament(String tournamentID, double prize) { // Initializing instance variable this.tournamentID=tournamentID; this.prize=prize; this.numTeamsRegistered=0; this.teams=new Team[MAX_TEAMS_REGISTERED]; } public String getTournamentID() { // This method return the tournament ID return this.tournamentID; } public int getNumTeamsRegistered() { // This method return the number of team registered in the tournament return this.numTeamsRegistered; } public void registerTeam(Team team) { if (numTeamsRegistered  

and to finish this class5

package tennis;

import java.util.*; import java.io.*;

public class Tennis {

private Scanner keyboard; private Tournament tournament; private Player[] players; private int numOfPlayers;

public static void main(String[] args) throws IOException { Tennis tennis = new Tennis(); System.out.println("***Name StudentNumber***"); System.out.println("*** Players ***"); tennis.run(); }

public Tennis() { keyboard = new Scanner(System.in); tournament = null; }

public void run() throws IOException { if (loadPlayersFromFile()) { int choice = -1; while (choice != 0) { displayMenu(); System.out.print("Enter choice >> "); choice = keyboard.nextInt(); System.out.println(); keyboard.nextLine(); process(choice); } } else { System.out.println("Players could not be loaded from file"); } }

private boolean loadPlayersFromFile() throws IOException { boolean fileExists = false; System.out.print("Enter name of player file: "); File playerFile = new File(keyboard.nextLine());

if (playerFile.exists()) { fileExists = true; Scanner playerFileScanner = new Scanner(playerFile); numOfPlayers = playerFileScanner.nextInt(); players = new Player[numOfPlayers]; playerFileScanner.nextLine(); for (int i = 0; i

players[i] = new Player(playerName, playerAge, playerCountryCode); } } return (fileExists); }

private void displayMenu() { System.out.println(); System.out.println(" ~~~~ TENNIS MENU ~~~ "); System.out.println("1. Display Loaded Players"); System.out.println("2. Add Tournament"); System.out.println("3. Add Team to Tournament"); System.out.println("4. Display Team"); System.out.println("5. Display Player"); System.out.println("6. Display Tournament"); System.out.println("7. Display Total Number of Teams"); System.out.println("0. Quit"); }

private void process(int choice) { if (choice == 1) { displayLoadedPlayers(); } else if (choice == 2) { addTournament(); } else if (choice == 3) { addTeamToTournament(); } else if (choice == 4) { displayTeam(); } else if (choice == 5) { displayPlayer(); } else if (choice == 6) { displayTournament(); } else if (choice == 7) { displayTotalNumberOfTeams(); } }

private void displayLoadedPlayers() { // TODO }

private void addTournament() { // TODO }

private void addTeamToTournament() { if (tournament != null) { if (tournament.getNumTeamsRegistered()

boolean foundIt = false; for (Player p : players) { if (p != null && p.getCountryCode().equalsIgnoreCase(countryCode)) { // TODO foundIt = true; } } if (!foundIt) { System.out.println("Invalid team number"); } } else { System.out.println("Tournament already Full"); } } else { System.out.println("No tournament"); } }

private void displayTeam() { System.out.println(); if (tournament != null) { System.out.print("Enter team name: "); String teamName = keyboard.nextLine();

boolean foundIt = false; Team[] teams = tournament.getAllTeams(); for (Team t : teams) { if (t != null && t.getTeamName().equalsIgnoreCase(teamName)) { System.out.println(t); foundIt = true; break; } } if (!foundIt) { System.out.println("Invalid team name"); }

} else { System.out.println("No tournament"); } }

private void displayPlayer() { // TODO }

private void displayTournament() { // TODO }

private void displayTotalNumberOfTeams() { // TODO } }

Background You are tasked with creating a system that manages the tennis player/team/tournament database. The system is menu driven. And the user can choose to: (to be done in Part 2) Add Player Start Tournament Add Team Add Manager to Team Sign Player Display Player Display Manager Display Team Display Total Number of Players The players are loaded into the system from a file at the start of running the program, and can not be changed once loaded. (to be done in Part 2) A player consists of its name, age and country code. A Team consists of a player and a manager A tournament can carry up to max Teams registered (8 in this example), it has an id and a prize. A manager has a name. When a Team is added, a tournament must exist. A Team can only have one manager. A tournament can only be started if there is at least 2 Teams and the tournament exist. Create each class following the UML diagram, descriptions and tests. A test class is provided for you to test two of the classes as you develop. If the entire program does not work, a similar version will be used for marking. Hence it is VERY important to get each working individual before proceeding to the next to maximize potential marks and feedback. It is recommended you add to the tests provided or create your own tests, to cover all possible scenarios. You must use the attributes and methods provided in the UML diagrams and base template You can add private helper methods if you want to any class Templates are provided for all classes required. A tester is provided for Team and Player classes. Three input files are provided Class 5 - Tennis.java Tennis Scanner keyboard - Tournament tournament - Player[ ] players - int numOfPlayers + static void main(String[] args) + Tennis() + void run() - void displayMenu() - void process(int choice) - boolean load Players FromFile() - void displayLoadedPlayers() - void addTournament() - void addTeam To Tournament) - void displayTeam() - void displayPlayer() - void display Tournamento) void display TotalNumberOfTeams() Methods *Methods provided fully with code must not be changed, except where explicitly stated. main (provided) Creates an instance of the Tournament Prints student information (Edit to your own information) and program name Calls the run method Tournament constructor (provided) Initializes attributes run (provided) Calls the method to load players from file Calls the method to display menu Gets users input Calls the method to process the users input displayMenu (provided) Displays the menu options process (provided) Calls the appropriate method based on the value passed load Players FromFile (provided) Loads players from files addTeam if tournament is null print "No tournament" Else if tournament has max Teams (8) registered, print "Tournament already full" Else Ask the user for the team name Ask the user for the country code Set a Boolean flag to false, for your search For each player in loaded players array, If player with such a country code exists Ask the user for the manager name Create a Manager object reference Create a Team object reference Set the manager to the new created Team Register the new Team to the tournament Set the Boolean flag to true, means founding this country code If team is not added (Boolean flag is still false, because the country code is not found) Display "invalid team name displayTeam if tournament is null print "No tournament" Else Ask the user for the team name Set a Boolean flag to false, for your search Get all the teams of tournament and store them in Array of Teams objects For each team in loaded teams array, If teams name matches the user entry Display the matched Team Set the Boolean flag to true, means founding this team If team is not added (Boolean flag is still false, because the team is not found) Display "invalid team name" display Player if tournament is null print "No tournament" Else Ask the user for the player name Set a Boolean flag to false, for your search For each player in loaded players array, If player name matches the user entry Display the matched Player Set the Boolean flag to true, means founding this player If team is not added (Boolean flag is still false, because the player is not found) Display "invalid player name" addTournament If tournament is not null, print a message stating that a tournament is already added Else Ask the user for the tournament id and prize, Create a new tournament instance Print a message to indicate that the tournament has been added displayTournament Display the tournament using the toString in the Tournament class displayTotalNumberOfTeams Display the total number of Teams using the static getTotalNumOfTeams method in the Team class, this should work even when there are no Teams, Background You are tasked with creating a system that manages the tennis player/team/tournament database. The system is menu driven. And the user can choose to: (to be done in Part 2) Add Player Start Tournament Add Team Add Manager to Team Sign Player Display Player Display Manager Display Team Display Total Number of Players The players are loaded into the system from a file at the start of running the program, and can not be changed once loaded. (to be done in Part 2) A player consists of its name, age and country code. A Team consists of a player and a manager A tournament can carry up to max Teams registered (8 in this example), it has an id and a prize. A manager has a name. When a Team is added, a tournament must exist. A Team can only have one manager. A tournament can only be started if there is at least 2 Teams and the tournament exist. Create each class following the UML diagram, descriptions and tests. A test class is provided for you to test two of the classes as you develop. If the entire program does not work, a similar version will be used for marking. Hence it is VERY important to get each working individual before proceeding to the next to maximize potential marks and feedback. It is recommended you add to the tests provided or create your own tests, to cover all possible scenarios. You must use the attributes and methods provided in the UML diagrams and base template You can add private helper methods if you want to any class Templates are provided for all classes required. A tester is provided for Team and Player classes. Three input files are provided Class 5 - Tennis.java Tennis Scanner keyboard - Tournament tournament - Player[ ] players - int numOfPlayers + static void main(String[] args) + Tennis() + void run() - void displayMenu() - void process(int choice) - boolean load Players FromFile() - void displayLoadedPlayers() - void addTournament() - void addTeam To Tournament) - void displayTeam() - void displayPlayer() - void display Tournamento) void display TotalNumberOfTeams() Methods *Methods provided fully with code must not be changed, except where explicitly stated. main (provided) Creates an instance of the Tournament Prints student information (Edit to your own information) and program name Calls the run method Tournament constructor (provided) Initializes attributes run (provided) Calls the method to load players from file Calls the method to display menu Gets users input Calls the method to process the users input displayMenu (provided) Displays the menu options process (provided) Calls the appropriate method based on the value passed load Players FromFile (provided) Loads players from files addTeam if tournament is null print "No tournament" Else if tournament has max Teams (8) registered, print "Tournament already full" Else Ask the user for the team name Ask the user for the country code Set a Boolean flag to false, for your search For each player in loaded players array, If player with such a country code exists Ask the user for the manager name Create a Manager object reference Create a Team object reference Set the manager to the new created Team Register the new Team to the tournament Set the Boolean flag to true, means founding this country code If team is not added (Boolean flag is still false, because the country code is not found) Display "invalid team name displayTeam if tournament is null print "No tournament" Else Ask the user for the team name Set a Boolean flag to false, for your search Get all the teams of tournament and store them in Array of Teams objects For each team in loaded teams array, If teams name matches the user entry Display the matched Team Set the Boolean flag to true, means founding this team If team is not added (Boolean flag is still false, because the team is not found) Display "invalid team name" display Player if tournament is null print "No tournament" Else Ask the user for the player name Set a Boolean flag to false, for your search For each player in loaded players array, If player name matches the user entry Display the matched Player Set the Boolean flag to true, means founding this player If team is not added (Boolean flag is still false, because the player is not found) Display "invalid player name" addTournament If tournament is not null, print a message stating that a tournament is already added Else Ask the user for the tournament id and prize, Create a new tournament instance Print a message to indicate that the tournament has been added displayTournament Display the tournament using the toString in the Tournament class displayTotalNumberOfTeams Display the total number of Teams using the static getTotalNumOfTeams method in the Team class, this should work even when there are no Teams

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

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899

More Books

Students also viewed these Databases questions