Due Date
Before Starting the Project
Learning Objectives
After completing this project, you should be able to:
Project Summary
Create a GUI application that allows someone to search a list of more than 10,000 Covid-19 data records. Each record contains seven items: state, month, day, daily infections, daily deaths, total infections, and total deaths for that state, up to that date. The database you create will allow health officials to determine all sorts of statistics related to the Covid-19 pandemic in the U.S. The data is from https://covidtracking.com
(March 1 – September 27, 2020)
Step 1: Create a New BlueJ Project called Project 3
Step 2: Download Data File
Step 3: Create a class called CovidEntry
NOTE: We are providing two JUnit classes to test your project. Exact spelling is required in the CovidEntry class. Do not change the method headers in any way.
The input parameters are:
NOTE: The following methods return the required value for a particular state, month, and day that is stored as part of the object.
Example:
NY 4/20 4,726 infections, 478 deaths
JUnit Testing
Download CovidEntryJUnit.java to the folder of your project and run the test case – testing the constructor.
Step 4: Create a class called CovidDatabase
Note: We are providing a JUnit class to test your project. Exact spelling is required in the CovidDatabase class for the class name and all the method headers. Do not change the method headers in any way.
Background Info: Reading Text Files
The first four lines of the data file are shown below. The first line provides descriptors for-each record. Read this line and do not assign it to any variable. Items are separated by commas. The database reads one item at a time. Note, the Scanner needs to be informed that commas, instead of blank spaces, will be used as a delimiter. A carriage return or new line character (aka the Enter key) is also used as a delimiter between each line.
Sample record of the covid_data.csv file: (first four records).
state,month,day,dailyInfect,dailyDeaths,totalInfect,totalDeaths
WA,3,1,16,3,34,8
VA,3,1,0,0,0,0
RI,3,1,0,0,2,0
Sample Method to Read a File
The following method reads from a text data file one line at a time. The solution is a bit more complex than shown in Section 14.4 because the book is hiding some necessary details. The data file for this example includes a name, an age and a GPA on one line separated by commas. Your solution for reading the COVID data will be similar.
Johnny,18,1.9
Mary,21,3.9
Jasmine,20,2.8
public void readCovidData(String filename) {
Scanner inFS = null; FileInputStream fileByteStream = null;
try{ // open the File and set delimiters fileByteStream = new FileInputStream(filename); inFS = new Scanner(fileByteStream); inFS.useDelimiter(“[,\r\n]+”);
//ignores the line of headers inFS.nextLine(); // continue while there is more data to read while(inFS.hasNext()) { String s = inFS.next(); int m = inFS.nextInt(); int d = inFS.nextInt(); int di = inFS.nextInt(); int dd = inFS.nextInt(); int ti = inFS.nextInt(); int td = inFS.nextInt(); db.add(new CovidEntry(s, m, d, di, dd, ti, td)); } fileByteStream.close(); // error while reading the file } catch(IOException error1) { System.out.println(“Oops! Error related to: ” + filename); } } |
Accessor Methods
Safe to Open
Public officials are encouraged by the U.S. Center for Disease Control to keep a state shut down until an appropriate downward trend in new daily infections is observed. The ideal goal is 14 days. Instead, we will use the lower threshold of only five consecutive days of decreasing daily infections. For program flexibility, declare a final instance variable that represents the required number of days. This can be changed easily by public officials.
private static final int SAFE = 5;
Generate a Top Ten List
This method requires sorting an ArrayList of CovidEntry objects in descending by number of daily deaths.
This requires changes to the CovidEntry and CovidDatabase classes.
public class CovidEntry implements Comparable{
Also, add the following method. This method allows two CovidEntry objects to be compared with respect to the number of daily deaths.
public int compareTo(Object other){
CovidEntry c = (CovidEntry) other;
return c.dailyDeaths – dailyDeaths;
}
Add the following method to CovidDatabase.
Collections.sort(list);
Once you have the list of all the daily deaths for the specific date sorted in descending by the number of deaths, you can do any of these three options to figure out the top ten states with the highest number of deaths for that date.
Coding Style (10 pts)
Good programming practice includes writing elegant source code for the human reader. Follow the GVSU Java Style Guide.
Step 5: Software Testing (10 pts)
To be able to test this project you need to know the results for a specific query. One strategy would be to create a test database with a few dozen records carefully crafted to test each method. For example, you create a specific record with the highest total deaths and confirm that the method returns this record.
However, we will provide sample results for your comparison.
Software developers must plan from the start that their solution is correct. BlueJ allows you to instantiate objects and invoke individual methods. You can carefully check each method and compare actual results with expected results. However, this gets tedious. Another approach is to write a main method that calls all the other methods.
Create a new class called CovidDatabaseTest with a main method.
Write a main method in a new class called CovidDatabaseTest that instantiates a CovidDatabase object and invokes each of the methods with a variety of parameters. It takes careful consideration to anticipate and test every possibility. This is an incomplete example. Your solution should be longer to test all methods in CovidDatabase.
public class CovidDatabaseTest {
public static void main () {
System.out.println (“Testing starts”);
CovidDatabase db = new CovidDatabase() ;
db.readCovidData(“covid_data.csv”);
// check number of records, total infections, and total deaths
assert db.countRecords() == 10346 : “database should have 10,346”;
assert db.getTotalDeaths() == 196696 : “Total deaths should be: 196,696”;
assert db.getTotalInfections() == 7032090 : “infections should be: 7,032,090”;
// check peak daily deaths for 5/5
CovidEntry mostDeaths = db.peakDailyDeaths(5, 5);
assert mostDeaths.getState().equals(“PA”) : “State with most deaths for 5/5 is PA”;
assert mostDeaths.getDailyDeaths() == 554 : “Deaths for 5/5 is PA: 554”;
// test other methods
System.out.println (“Testing ends”);
}
}
Sample Results – data from Mar 1 – Sep 27, 2020
Method | Results |
countRecords () | 10,346
|
getTotalDeaths () | 196,696
|
getTotalInfections () | 7,032,090
|
mostTotalDeaths() | NY with 25,456 deaths
|
peakDailyDeaths (“MI”) | MI 4/16 922 infections, 169 deaths
|
peakDailyDeaths (5 , 5) | PA 5/5 865 infections, 554 deaths
|
topTenDeaths (5, 5) | Top Ten Daily Deaths for 5/5
PA 5/5 865 infections, 554 deaths NJ 5/5 2,324 infections, 341 deaths NY 5/5 2,239 infections, 230 deaths IL 5/5 2,122 infections, 176 deaths CT 5/5 1,334 infections, 138 deaths MA 5/5 1,184 infections, 122 deaths FL 5/5 542 infections, 113 deaths OH 5/5 495 infections, 79 deaths GA 5/5 343 infections, 66 deaths CA 5/5 1,275 infections, 63 deaths |
safeToOpen (“MI”) | MI is safe to open
MI 5/26 443 infections, 25 deaths MI 5/27 386 infections, 24 deaths MI 5/28 336 infections, 24 deaths MI 5/29 319 infections, 27 deaths MI 5/30 205 infections, 24 deaths |
listMinimumDailyInfections(6,12,1000) | All states with at least 1000 infections on 6/12
TX 6/12 2,097 infections, 19 deaths NC 6/12 1,768 infections, 28 deaths FL 6/12 1,902 infections, 29 deaths CA 6/12 2,702 infections, 62 deaths AZ 6/12 1,654 infections, 17 deaths
|
JUnit Testing
Download CovidDatabaseJUnit.java to the folder of your project and run the test cases.
Step 6: Complete a CovidDatabaseGUI class (15 pts)
Now that you have the Database working in its own class, it is time to create a more interesting graphical user interface (GUI) for someone to use. Once again, we provide you a starting template. Read the code for clues on how to position the other elements. Read Zybooks – sections 10.1 – 10.3 and the additional link at the end of section 10.2 – How To Use GridBag Layout.
Additional instance variables
Changes to main()
Changes to the constructor
Changes to setupMenus()
Changes to actionPerformed(). See the FIX ME comment.
if (e.getSource() == peakBtn){
displayPeakDeaths();
}
Add helper methods
Figure 1. GUI layout
Helper Methods
Helper methods keep the code easy to read by hiding details away in other areas of the program. These methods work with the Database to display results within the results text area using setText() and appendText(). For example:
int total = database.countTotalDeaths(5,23);
results.setText(“Total U.S. Deaths\n”);
results.append(total);
Step 7: Enhance the GUI (5 pts)
The following should only be attempted after all the other requirements have been completed.
Check for Valid Input
The basic GUI assumes that all values provided by the user are valid integers. If not, the program crashes. A better solution is to confirm values are valid integers BEFORE attempting to convert from a String to an integer and then passing to the database
Update each helper method that attempts to convert a text field to an integer (Figure 2). For example:
if (isValidMonth())
// valid integer entered in month text field
// OK to pass as parameter to database
Figure 2. Sample error message
Grading Criteria
There is a 50% penalty on programming projects if your solution does not compile.
Late Policy
Projects are due at the START of the lab period. However, you are encouraged to complete a project even if you must turn it in late.
Submit to Blackboard
Project 3.zip,
and your filled in Word Document
Project 3A Summary.docx
to Blackboard folder
Assignments > Projects > Project 3 > P3A
Project 3.zip,
and your filled in Word Document
Project 3B Summary.docx
to Blackboard folder
Assignments > Projects > Project 3 > P3B
Project 3.zip,
and your filled in Word Document
Project 3C Summary.docx
to Blackboard folder
Assignments > Projects > Project 3 > P3C
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more