Question
.csv file: all-states-history.csv (if you google, it should be found) The program should be called SearchCOVIDData. It should have at least the following methods: findRow
.csv file: all-states-history.csv (if you google, it should be found)
The program should be called SearchCOVIDData. It should have at least the following methods:
findRow Write a method called findRow that takes as input the two strings that the user entered: the date and the state, and returns the whole row that matches from the data base. The row should be returned as a string. If no row matches the state and date, then findRow should return an empty string. In findRow, use a loop controlled by hasNext() to search through the data file. (Note that this will always search the whole data file, even if it finds the appropriate data. Think about how you might get it to stop searching once it finds the data.)
getStateName
Write a method called getStateName that takes a states abbreviation as input and returns the
whole state name as output. You only have to handle CA, OR, HI, and WA. But you can get
extra credit for handling all 50 states. (Hint: Think about switch()).
getColumn
Write a method called getColumn which returns the data that is at a particular column in a
comma-separated string. The first argument to getColumn should be the desired column
number, and the second argument should be a whole row from the data file. For example,
if String row = one,two,three,four,five
then getColumn(2,row), should return two
Hint: you can use a Scanner to examine the elements in a string. The next() method will jump to
each next element. In order to tell the Scanner to use commas as the delimiter between elements,
define it like this (if
line
is a comma-separated string):
Scanner in = new Scanner(line).useDelimiter(\",\");
Call next() twice to get to the second element, three times to get to the third, etc. Note that next()
always returns a string, so any numerical data that is obtained using next() must be converted if
it is going to be used in as a number.
Big hint: You can put calls to next() in a loop if you want to call it more than once.
main
fixDate (optional extra credit)
As mentioned above, the date data in the file has no leading zeros on the months of the days. For
example, it has 2/2/21 instead of 02/02/21. This means that the user input has to match perfectly,
or else you must modify it to match what is in the data file. fixDate would take the date that a
user input and fix it (if necessary) so that it matches the format of the data file. For example,
02/02/21 would be changed to 2/2/21. This is pretty hard, so extra credit if you can do it!
Obviously, you will have a main method! First your main method needs to get user input. Next
it should call findRow to try and get the appropriate row from the table. Note that you have to
fix any user input (i.e. state abbreviations or dates) before you try matching the data to the
database either before calling findRow or someplace in findRow. (Hint: the String method
toUpperCase() will change any string to all upper case.) If a row is not matched, the program is
done and must print that it failed to find the data. If the row is matched, then you next have to
pretty-print it. You must call getStateName before or inside the print statement in order to get
the state name to print right. You will need to convert the numbers from strings in order to print
them with commas.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started