Question: In this project, you are expected to build a small database that stores data related to NBA coaches and teams. Users can send simple queries
In this project, you are expected to build a small database that stores data related to NBA coaches and teams. Users can send simple queries to this database, and add new data to the database. The database has two tables (or relations) - one for coaches and one for teams. The schemas for the two tables are as follows (and you must follow the schemas in this project): coaches (Coach_ID : consists of less than 7 capital letters and two digits, season : 4 digit year, first_name : any reasonable English name , last_name : any reasonable English name, season_win : non-negative integer, season_loss : non-negative integer, playoff_win : non-negative integer, playoff_loss : non-negative integer, team : capital letters and/or digits) teams (team_ID : capital letters and/or digits, Location : American City name, one or two English word(s), Name : team name, any reasonable English word, League : one capital letter) Your database should have a command-line interface to allow users to add data and send in queries. The interface accepts the following commands: 1. add_coach: add a new record describing the performance of one coach in one season. It should have the following 9 arguments: ID SEASON FIRST_NAME LAST_NAME SEASON_WIN SEASON_LOSS PLAYOFF_WIN PLAYOFF_LOSS TEAM, the types of which should match the schema of relation "coaches" mentioned above ;
2. add_team: add a new record with one team's basic information. It should be followed by the following 4 arguments: ID LOCATION NAME LEAGUE, the types of which should match the schema of the "teams" table;
3. load_coaches : bulk load of multiple coach/season records from a file specified by the only argument of the command. Note that the file stores each record in one line of text, and different fields of the line/record are separated by commas. In our sample files, you may find empty attribute values (nothing in between two commas) and you should still load that line into your database instead of rejecting it.
4. load_teams : bulk load of multiple team records from a file specified by the only argument of the command. Records in such files are organized in the same way as in those for load_coaches.
5. print_coaches: print a list of all coaches, with info about one coach's performance in one season in a line; 6. print_teams: print a list of all teams, with info about one team per line; 7. coaches_by_name : print the information of coach(es) with the specified last name, which is given by the only argument of this command; 8. teams_by_city : print the information of teams in the city specified by the only argument; 9. best_coach: print the name of the coach who has the most net wins in a season specified by the only argument. Note that the net wins should be calculated as (season_win - season_loss) + (playoff_win - playoff_loss). 10. search_coaches: print the info of coaches with the specified properties, which are given by the arguments in the following format: field=VALUE where field represents the name of a search criterion and 'VALUE' is the value of that field you want the query results to match. Multiple fields can be used in the same query. For example, a command "search_coaches first_name=John season_win=40" means "finding all performance data of a coach with first name 'John' who had a seasonal win of 40". Note that a meaningful field should match exactly one of the column names in the coaches table (just ignore those that do not match any column names).
public class P1 { /* Define data structures for holding the data here */
public P1() { /* initialize the data structures */ } public void run() { CommandParser parser = new CommandParser();
System.out.println("The mini-DB of NBA coaches and teams"); System.out.println("Please enter a command. Enter 'help' for a list of commands."); System.out.println(); System.out.print("> "); Command cmd = null; while ((cmd = parser.fetchCommand()) != null) { //System.out.println(cmd); boolean result=false; if (cmd.getCommand().equals("help")) { result = doHelp();
/* You need to implement all the following commands */ } else if (cmd.getCommand().equals("add_coach")) { } else if (cmd.getCommand().equals("add_team")) { } else if (cmd.getCommand().equals("print_coaches")) {
} else if (cmd.getCommand().equals("print_teams")) {
} else if (cmd.getCommand().equals("coaches_by_name")) {
} else if (cmd.getCommand().equals("teams_by_city")) {
} else if (cmd.getCommand().equals("load_coaches")) {
} else if (cmd.getCommand().equals("load_teams")) { } else if (cmd.getCommand().equals("best_coach")) {
} else if (cmd.getCommand().equals("search_coaches")) {
} else if (cmd.getCommand().equals("exit")) { System.out.println("Leaving the database, goodbye!"); break; } else if (cmd.getCommand().equals("")) { } else { System.out.println("Invalid Command, try again!"); } if (result) { // ... }
System.out.print("> "); } } private boolean doHelp() { System.out.println("add_coach ID SEASON FIRST_NAME LAST_NAME SEASON_WIN "); System.out.println(" EASON_LOSS PLAYOFF_WIN PLAYOFF_LOSS TEAM - add new coach data"); System.out.println("add_team ID LOCATION NAME LEAGUE - add a new team"); System.out.println("print_coaches - print a listing of all coaches"); System.out.println("print_teams - print a listing of all teams"); System.out.println("coaches_by_name NAME - list info of coaches with the specified name"); System.out.println("teams_by_city CITY - list the teams in the specified city"); System.out.println("load_coach FILENAME - bulk load of coach info from a file"); System.out.println("load_team FILENAME - bulk load of team info from a file"); System.out.println("best_coach SEASON - print the name of the coach with the most netwins in a specified season"); System.out.println("search_coaches field=VALUE - print the name of the coach satisfying the specified conditions"); System.out.println("exit - quit the program"); return true; } /** * @param args */ public static void main(String[] args) { new P1().run(); }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
