project 3
CIS 162 Project 3 Olympic Medalists Database Due Date See due date for your section on Blackboard. Suggested guidelines for time required for each phase: Phase 1 – one day Phase 2 – two weeks Phase 3 – one day Before Starting the Project You are responsible for understanding and adhering to the School of CIS Guidelines for Academic Honesty. Read chapters 10 and 11 – GUI and ArrayLists Read this entire project description before starting Learning Objectives After completing this project, you should be able to: use ArrayLists to maintain and process collections of objects use for-each loops/enhanced for loops read data from external text files Olympic Medalists We are providing a dataset (.csv file) with the records for the Summer Olympics Medals (1976- 2008). This dataset is a list of all the medal winners in the Summer Olympics from 1976 Montreal to 2008 Beijing. It includes each medal awarded within the period. The dataset was downloaded from http://www.key2stats.com/. The original file was edited to clean the data to be able to work with the project. Project Overview You will read a file to create a collection of Olympic Medalists and a collection of total medals by country. Once you have created the collections, you will be able to ask questions like: how many medalists do we have in the collection, find a particular Olympic medalist, search for the Olympic medalists that participated in a specific Olympic game, find the medalists for a specific country, find the top 10 countries with gold medals in a specific year, etc. This project has the following classes: OlympicMedalist – class to handle the information about the individual medalist Fall 2021 - CIS 162 Project 3 Olympic Medalists Database Page 1 of 11 https://www.cis.gvsu.edu/academic-honesty/ https://www.cis.gvsu.edu/academic-honesty/ http://www.key2stats.com/ OlympicCountryMedals – class to handle the total gold, silver and bronze medals for a country participating in a specific Olympic game OlympicMedalistDatabase – class that reads the input file and creates the collections of medalists and medal totals OlympicMedalistsGUI – class that handles the GUI to read the input file, and run the queries associated with the collection of medalists and medal totals Create a New BlueJ Project Download Data File Download the “SummerOlympicsMedals.csv” file and save it in the folder that BlueJ created for this project. There are over 15,000 records! You will not see the file within BlueJ but you can see it from within Windows Explorer. Coding Style (10 pts) Good programming practice includes writing elegant source code for the human reader. Follow the GVSU Java Style Guide. Phase 1 (20 pts) Important note: Exact spelling is required for the name of the OlympicMedalist, OlympicCountryMedals and the OlympicMadalistsDatabase classes and the headers of all the methods within these classes. Do not make any changes to the following requirements. If you do so, the automated tests that we provide will likely fail. Create a class called OlympicMedalist This class will store the data for a specific summer Olympic medalist. Instance Variables: city (String) year (int) sport (String) discipline (String) event (String) athlete name (String) gender (String) country code (String) medal (String) Fall 2021 - CIS 162 Project 3 Olympic Medalists Database Page 2 of 11 https://www.cis.gvsu.edu/java-coding-style-guide/ Constructor public OlympicMedalist (String data) - a constructor that initializes all the instance variables to appropriate values. The input parameter is a String that contains the values of an Olympic medalist. Each value is separated by a comma. You need to parse the string data into the individual fields. The order of the fields in the string is: city, year, sport, discipline, event, athlete name, gender, country code and medal. Hint: Use the split method of the string class using comma as the delimiter to parse the string entered as input parameter into the individual fields. Example of the data entered as input parameter. "Montreal,1976,Aquatics,Diving,3m springboard,BOGGS Philip George,Men,USA,Gold" Accessor/getter Methods public String getCity() – returns the Olympic games city public int getYear() – returns the Olympic games year public String getSport() – returns the sport public String getDiscipline() – returns the discipline public String getEvent() – returns the event public String getName() – returns the athlete name public String getGender() – returns the athlete gender public String getCountryCode() – returns the athlete country code public String getMedal() – returns the athlete medal Setter Methods You do not need to include any setters for this class. More methods public String toString() - return a formatted String of an Olympic medalist. Do not print, return a string concatenating the individual wanted fields. See example. For example: Montreal 1976 Country: USA Sport: Aquatics Event: 3m springboard Name: BOGGS Philip George, Gold Create a class called OlympicCountryMedals This class will store the total number of gold, silver and bronze medals for each country participating in a specific Olympic game. Instance Variables: city (String) year (int) country code (String) goldMedals (int) Fall 2021 - CIS 162 Project 3 Olympic Medalists Database Page 3 of 11 silverMedals (int) bronzeMedals (int) Constructor public OlympicCountryMedals(int year, String city, String countryCode, int goldMedals,int silverMedals, int bronzeMedals) - a constructor that initializes all the instance variables to appropriate values of the input parameters. Accessor/getter Methods public String getCity() – returns the Olympic games city public int getYear() – returns the Olympic games year public String getCountryCode() – returns the country code public int getGoldMedals() – returns the total gold medals public int getSilverMedals() – returns the total silver medals public int getBronzeMedals() – returns the total bronze medals Setter Methods You do not need to include any setters for this class. More methods public String toString() - return a formatted String of an Olympic Country Medals. Do not print, return a string concatenating the individual wanted fields. See example. For example: 2008 Beijing, USA, Gold: 125, Silver: 109, Bronze: 81 Test Phase 1 using the automated JUnit class Download the MyOlympicMedalistTestPhase1.java to the folder where you saved your project 3 and test your solution. See instructions from project 1 to know how to run a JUnit class. Note: You do not need to create your own class to test phase1 of your project. Phase 2 (50 pts) Create a class called OlympicMedalistsDatabase This class maintains: an ArrayList of OlympicMedalist objects an ArrayList of OlympicCountryMedals objects Instance Variables Declare an ArrayList of OlympicMedalist objects Declare an ArrayList of OlympicCountryMedals Fall 2021 - CIS 162 Project 3 Olympic Medalists Database Page 4 of 11 Constructor public OlympicMedalistsDatabase () - instantiate the two ArrayLists declared as instance variables. Mutator Methods public void readOlympicMedalistData(String filename) - open the provided filename given as input parameter, use a loop to read all the data in the file, create a OlympicMedalist object for each record and add it to the ArrayList. We are providing most of the code for this method. Look for the TO DO comment to complete the logic. Background Information: Reading from a Text File The readOlympicMedalistData method reads one line at the time. Each line contains 9 items that are separated by commas. This method passes the line (record) read to the OlympicMedalist class constructor and adds the OlympicMedalist object to the ArrayList. Sample record: "Montreal,1976,Aquatics,Diving,3m springboard,BOGGS Philip George,Men,USA,Gold" public void readOlympicMedalistData(String filename) { // Read the full set of data from a text file try{ // open the text file and use a Scanner to read the text FileInputStream fileByteStream = new FileInputStream(filename); Scanner scnr = new Scanner(fileByteStream); scnr.nextLine(); // reads the column headers // keep reading as long as there is more data while(scnr.hasNext()) { // reads each record of the file String data = scnr.nextLine(); // TO DO: instantiates an object of the OlympicMedalist class // and add it to the ArrayList of OlympicMedalists } generateCountryTotalMedals(); //This method will be written later fileByteStream.close(); } catch(IOException e) { System.out.println("Failed to read the data file: " + filename); } } Accessor Methods public int countAllMedalists () - return the number of Olympic medalists found in the database using one line of code. public int countAllWomen() – Use a for-each loop to search the full list of Olympic medalists and count the total number of women Olympic medalists. Fall 2021 - CIS 162 Project 3 Olympic Medalists Database Page 5 of 11 public int countAllMen() – Use a for-each loop to search the full list of Olympic medalists and count the total number of men Olympic medalists. public ArrayList
getMedalistsDatabase()- return the ArrayList of OlympicMedalists. One line of code. public ArrayList getCountryTotalMedalsDatabase()- return the ArrayList of OlympicCountryMedals. One line of code. public ArrayList searchMedalistsByYear(int year)– Use a for-each loop to search the full list of Olympic medalists and return a new list of Olympic medalists for the year entered as input parameter. If there is no match for the year, the returned list will exist but have zero elements.