Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Project # 4 Pitcher Stats Database using a Binary Search Tree You are to create a Program that simulates a Database with baseball pitchers information

Project # 4 Pitcher Stats Database using a Binary Search Tree You are to create a Program that simulates a Database with baseball pitchers information that is stored in a Binary Search Tree. Summary of program: Your program will start with reading a csv input file filled with pitcher stats. Each line of this file will contain the needed information to create a pitcher object. The first line of this file defines what data is in the columns. This file will be given to you. As each line of the file is read, you will create a Pitcher object and place it in the Binary Search Tree. Then a menu will be displayed giving you choices to display pitcher information, update, remove, or add new pitcher. When quit is chosen the contents of your binary search tree will be traversed and output to update the same datafile. (You will be writing over the original data) You may want to create a file of a different name for testing purposes, so that you do not corrupt the original file during debugging.) Pitcher class: The Pitcher class will contain the following private data variables: - lastname (String) - firstname (String) - team (String) - #games pitched - #games won (int) - #shutouts (int) - #innings pitched (double) - #hits - #earned runs (int) - #strikeouts (int) - ERA (double) You will calculate the value of ERA in the constructor from the data in the file. The math is: ERA = #earned runs / #innings pitched * 9 Remember to use double precision math. The Pitcher class must also contain the following methods: - constructor that takes a line from the CSV file - constructor that takes only a first name, last name, and a team abbreviation - accessors for each of the variables - modifiers for each of the variables - method to add the results of a new game, i.e., was the game a win? was the game a shutout? increment the number of innings pitches, the number of earned runs, the number of strikeouts, and automatically update the ERA. - compareTo method to help sort (class will implement Comparable) - toString that will convert to one string all of the stored info You may wish to add other methods to the Pitcher class for your own use. To create the Binary Search Tree you will be using the BTNode class given to you and you will be finishing methods in the template class TreeBag. In the TreeBag class you only need to implement methods that you will be using for this project. You are not required to implement the rest of the methods in the class. You may leave them as program stubs and ignore. Make sure all references to Pitcher objects are generic ones. I have written Pitcher_Object in as the parameters so that you better understand what each method is doing, but in the actual Treebag class they should be listed as E. Among the methods that you will need to create are: public void add (Pitcher_Object) You will be adding pitchers in the tree to locations based on the pitchers lastname, but there is method in the Pitcher class that you have created already called compareTo. Therefore you should use the compareTo method to compare this new pitcher to pitchers already within the tree. public Pitcher_Object retrieve (Pitcher_Object). The retrieve method will search the Binary Search tree for the element, the method will return the object that was found. If the object is not found the method returns null. You will need to create a Pitcher object with only the lastname and firstname, in order to do the search. I created an extra constructor for this task. When compareTo gives a zero, you know that you have found the correct Node. public boolean remove (Pitcher_Object) The remove method returns boolean therefore you need first find if the object is in the tree, if not return false, if yes, then delete the node from the tree and return true. Make careful sure that after Pitcher removal you still have a valid binary search tree. (Handle all cases) public void display() Display the pitcher name and his ERA in alphabetical order based on the lastname (think of the appropriate traversal through the tree to get this) You may want to create other methods that you will be using in the TreeBag class. You are to make use of the following class that we have discussed without making any changes. These classes are stored in the project folder. BTNode(unaltered) You will create these classes to finish the project: Pitcher (explained above) TreeBag (template given) PitcherStatsTree - main driver of program. The main driver was described above and contains the main menu which must contain the following choices: Menu choices: 1. Display listing to screen of all pitchers stats (ordered by lastname) 2. Display the pitchers in current tree format (Use displayAsTree ) 3. Find and display one individual pitchers stats 4. Update an individual pitchers stats (by adding results of a new game) 5. Remove a pitcher from the Database 6. Add a new pitcher to the Database 7. Quit and update datafile The Datafile used is data stored in a CSV (comma separated values) text format, similar to what you have seen in previous assignments, with one pitcher on each line and commas between fields. It is organized like this: lastname,firstname,team,games_pitched,games_won,win_pct,shutouts,innings_pitched,hits,earnedruns,strikeouts Commas are used to separate the individual columns; the first line gives the column names be sure to skip the first line when reading this file. You can ignore the WIN_PCT column. The sample data file given is called pitcherstats.txt and will be used as a starting point to test your program. A copy of this file is given in with these program directions. Tips for good grades: Make sure you use comments where needed and use variable names that make sense, some of your grade will depend on program style as well as the use of your program. Update the comments in the class file, to include your names and any new information You will lose points for things like not indenting, or naming variables in non-descriptive ways. Do no leave in debugging code, or commented out code. I use jGrasp and the java version that is in the lab computers. So make sure that your programs work with this. Test your own projects thoroughly before you hand them in. Late projects will not be accepted so plan ahead. The four classes you ar using for this project should bein separate files. Name them PitcherStatsTree.java, Pitcher.java , TreeBag.java andBTNode.java. If you do not name these files correctly, you will lose points.

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

Students also viewed these Databases questions

Question

=+5 Does this case provide an example of the future for IHRM?

Answered: 1 week ago