Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*********NEED CODED IN C++************ COP 4710 Databases, Spring 2018 Project 1 : The NBA Stats Database (Due: 11:30pm, 01/23/2018) 1. Description In this project, you

*********NEED CODED IN C++************

COP 4710 Databases, Spring 2018

Project 1 : The NBA Stats Database (Due: 11:30pm, 01/23/2018)

1. Description 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). A coach's last name can be two words with a space in between (e.g., van Gundy). Your code should be able to handle this. There will be testcases that search by such names. In order to not confuse your program, we will add a "+" sign between the two words of the last name in the testcases. For example, coaches_by_name van+Gundy Obviously, your job here would be to process the argument by replacing the "+" sign with a space before you do the search. The same should be done for city names and other commands such as add_coach and add_team. 2. Getting Started To get started, you can download a package (a compressed file named proj1.tar) from the proj1 folder under 'Files' in Canvas. This package basically contains a Java command parser that will help you process the commands and their arguments. In other words, if you choose to program in Java, the whole command line interface is there for you to use - you only need to define data structures and code the individual commands. In case you are not aware, the java package you download should work as follows: you first unzip it and under the directory with all the unzipped files you can type javac *.java to compile the java code. If everything compiles, you can type java P1 to execute the program. At this moment, you will see a prompt in your console - now you can test your database commands. If you choose to program in another language, your program should work in the same way (once the program is executed, it always waits for a command input). The package also contains two sample input files: teams.txt and coaches_season.txt. You can take a look at both files to see what kind of data will be used to test your program. Note that both files use "," to separate the attributes in each record. You should get rid of them in loading the files into your database (e.g., using load_coach and load_team). Furthermore, data records in the file coaches_season.txt contain one attribute that we do not use in our schema - the 4th attribute with single-digit values. You should ignore them in loading and/or printing coach lists. Our testcases for load_coach and load_team will use files with the same formats as those in teams.txt and coaches_season.txt.

---------------------------------------------------------------------------------------------------------------------------------------------------

teams.txt

team,location,name,leag ANA,Anaheim,Amigos,A AND,Anderson,Duffey Packers,N ATL,Atlanta,Hawks,N BA1,Baltimore,Bullets,N BAL,Baltimore,Bullets,N BOS,Boston,Celtics,N BUF,Buffalo,Braves,N CAP,Capital,Bullets,N CAR,Carolina,Cougars,A CH1,Chicago,Stags,N CH2,Chicago,Zephyrs,N CHA,Charlotte,Hornets,N CHI,Chicago,Bulls,N CHR,Charlotte,Bobcats,N CIN,Cincinnati,Royals,N CL1,Cleveland,Rebels,N CLE,Cleveland,Cavaliers,N DAL,Dallas,Mavericks,N DE1,Detroit,Falcons,N

---------------------------------------------------------------------------------------------------------------------------------------------------

coaches.txt

coachid,year,yr_order,firstname,lastname,season_win,season_loss,playoff_win,playoff_loss,team RUSSEJO01 ,1946,1,John,Russell,22,38,0,0,BOS OLSENHA01 ,1946,1,Harold,Olsen,39,22,5,6,CH1 DEHNEDU01 ,1946,1,Dutch,Dehnert,17,20,0,0,CL1 CLIFFRO01 ,1946,2,Roy,Clifford,13,10,1,2,CL1 CURTIGL01 ,1946,1,Glenn,Curtis,12,22,0,0,DE1 SACHSPH01 ,1946,1,Philip,Sachs,8,18,0,0,DE1 COHALNE01 ,1946,1,Neil,Cohalan,33,27,2,3,NYK GOTTLED01 ,1946,1,Eddie,Gottlieb,35,25,8,2,PH1 BIRCHPA01 ,1946,1,Paul,Birch,15,45,0,0,PIT MORRIRO01 ,1946,1,Robert,Morris,28,32,0,0,PRO LOEFFKE01 ,1946,1,Ken,Loeffler,38,23,1,2,ST1 FITZGDI01 ,1946,1,Dick,Fitzgerald,2,1,0,0,TO1 SADOWED01 ,1946,2,Ed,Sadowski,3,9,0,0,TO1 HAYMALE01 ,1946,3,Lew,Hayman,0,1,0,0,TO1 ROLFERO01 ,1946,4,Robert,Rolfe,17,27,0,0,TO1 AUERBRE01 ,1946,1,Red,Auerbach,49,11,2,4,WSC JEANNBU01 ,1947,1,Buddy,Jeannette,28,20,9,3,BA1 RUSSEJO01 ,1947,1,John,Russell,20,28,1,2,BOS OLSENHA01 ,1947,1,Harold,Olsen,28,20,3,4,CH1 LAPCHJO01 ,1947,1,Joe,Lapchick,26,22,1,2,NYK GOTTLED01 ,1947,1,Eddie,Gottlieb,27,21,6,7,PH1 HICKENA01 ,1947,1,Nat,Hickey,4,25,0,0,PRO SOARAL01 ,1947,2,Albert,Soar,2,17,0,0,PRO LOEFFKE01 ,1947,1,Ken,Loeffler,29,19,3,4,ST1 AUERBRE01 ,1947,1,Red,Auerbach,28,20,0,0,WSC

---------------------------------------------------------------------------------------------------------------------------------------------------

P1.java

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();

} 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("SEASON_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();

}

}

---------------------------------------------------------------------------------------------------------------------------------------------------

Command.Java

/**

* Data container for an individual Command

*

* @author dbettis

*/

public class Command {

public Command(String command, String[] parameters) {

super();

this.command = command;

this.parameters = parameters;

}

public String getCommand() {

return command;

}

public String[] getParameters() {

return parameters;

}

public String toString() {

StringBuffer sb = new StringBuffer();

sb.append("Command: " + command + " ");

for (int i = 0; i < parameters.length; i++) {

sb.append("parameters[");

sb.append(i);

sb.append("] = ");

sb.append(parameters[i]);

sb.append(" ");

}

return sb.toString();

}

private String command;

private String[] parameters;

}

---------------------------------------------------------------------------------------------------------------------------------------------------

CommandParser.Java

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

public class CommandParser {

public Command fetchCommand() {

try {

String s = reader.readLine();

if (s == null) {

return null;

}

// \s+ = 1 or more of a whitespace char

String[] pieces = s.split("\\s+", 10 /* max command len + 1 */);

String[] params = new String[pieces.length - 1];

System.arraycopy(pieces, 1, params, 0, pieces.length - 1);

return new Command(pieces[0], params);

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return null;

}

private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

}

--------------------------------------------------------------------------------

Update:

You can assume the database system you are building works in-memory only.

-----------------------------------------------------------------------------------

Everything is stored in memory during execution of the program. When the program exits, the memory is not required to be stored.

This does not use any database management system.

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

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions

Question

Which of the following pairs of states has higher entropy?

Answered: 1 week ago

Question

=+6. Select the one that would work best for this client.

Answered: 1 week ago