Programming language: Java
Assignment 8 Objectives: Using a two-dimensional array o Declaring a 2D array o Assigning values to array elements o Traversing a 2D array to print the elements in a table Passing an array reference to a method Assignment Date: Tuesday, March 2 Due Date: Tuesday, March 9 (by 11:55 pm) Late assignment: 50% penalty Not accepted after: Wednesday, March 10 (by 11:55 pm) In this assignment, you will again use the "all-states-history-new.csv" file. Your goal will be to read in a date from the user, then read from the file and print a table of cases, hospitalizations, and deaths on that date for all states, districts, and territories. But, instead of printing it directly as the file is read, the data to be printed will be stored in a 2D-array and then the entire array will be printed For every date in the file, there is data for 50 states, the District of Columbia (DC), and five territories: American Samoa (AS), Guam (GU), Northern Mariana (MP), Puerto Rico (PR), U.S. Virgin Islands (VI). The table you want to print will be 56x4 (not counting the header), with each row representing a place and each column representing the data from that place. Here is an example for the date 2021-02-12 (with the middle rows left out): Enter a date (YYYY-MM-DD): 2021-02-12 State Cases Hosp Deaths AK 148 3 2 AL 1097 242 159 AR 565 23 13 AS 0 0 0 AZ 2426 141 172 CA 10059 0 546 CO 2091 48 9 CT 838 0 27 55 WI 1102 467 107 11 13 0 0 2 WY Details Write a program called COVIDTable which will print tables for specific dates as described above. COVIDTable should have the following main method: public static void main(String[] args) throws FileNotFoundException { String[] [] table = new String[56] [4]; String date = getDate(); getData(date, table); printTable(table); } You cannot have anything else in your main method! In other words, you must write the appropriate support methods. getDate is how you should get the date from the user. Then you return the date as a string to the main method. The code will be the same as you have already written many times before, but you are just moving it to a method getData is a method that will read from the data file, select the appropriate data for the table, and put all the data for the table into a 2D array. You must send it the date and a reference to the table array as shown. Note that when you declare the table array in the main method, all of the elements are empty. you pass the table reference to the getDat method, whatever the array argument is in getData, it will refer to the same data array as table. So, you can add data to the 2D array in the getData method and you do not need to return anything back to main. The fact that multiple variable names can refer to the same array is one of the central learning concepts for this assignment. (Hint: Since this method reads from a file, it also can throw a FileNotFoundException.) printTable is a method that pretty-prints the array. After printing the header, it will have to run through the rows and columns and print each element with the appropriate spacing. Give each column 10 spaces and be sure they are left justified as shown in the example runs. getColumn is a method that you have already written for previous assignments. You should reuse it here when you are getting the abbreviation for each state (column 1), the number of cases (column 22), the number of hospitalizations (column 10), and the number of deaths (column 5). It takes the column number as an integer and a whole row as a String, and then returns the data element from the specified column as a String. You will not be calling it from main, so think about which other method should use it. When Example Runs (There would be 56 rows, plus the header row, in each run.) Enter a date (YYYY-MM-DD): 2021-02-12 State Cases Hosp Deaths AK 148 3 2 AL 1097 242 159 AR 565 23 13 0 0 0 AS 11 WI WV WY 1102 467 107 55 0 2 13 0 Enter a date (YYYY-MM-DD): 2020-11-15 State Cases Hosp Deaths 642 7 AL 1979 8 2 AR 2722 35 AK 29 WI 155 6320 867 613 12 8 WV WY Assignment 8 Objectives: Using a two-dimensional array o Declaring a 2D array o Assigning values to array elements o Traversing a 2D array to print the elements in a table Passing an array reference to a method Assignment Date: Tuesday, March 2 Due Date: Tuesday, March 9 (by 11:55 pm) Late assignment: 50% penalty Not accepted after: Wednesday, March 10 (by 11:55 pm) In this assignment, you will again use the "all-states-history-new.csv" file. Your goal will be to read in a date from the user, then read from the file and print a table of cases, hospitalizations, and deaths on that date for all states, districts, and territories. But, instead of printing it directly as the file is read, the data to be printed will be stored in a 2D-array and then the entire array will be printed For every date in the file, there is data for 50 states, the District of Columbia (DC), and five territories: American Samoa (AS), Guam (GU), Northern Mariana (MP), Puerto Rico (PR), U.S. Virgin Islands (VI). The table you want to print will be 56x4 (not counting the header), with each row representing a place and each column representing the data from that place. Here is an example for the date 2021-02-12 (with the middle rows left out): Enter a date (YYYY-MM-DD): 2021-02-12 State Cases Hosp Deaths AK 148 3 2 AL 1097 242 159 AR 565 23 13 AS 0 0 0 AZ 2426 141 172 CA 10059 0 546 CO 2091 48 9 CT 838 0 27 55 WI 1102 467 107 11 13 0 0 2 WY Details Write a program called COVIDTable which will print tables for specific dates as described above. COVIDTable should have the following main method: public static void main(String[] args) throws FileNotFoundException { String[] [] table = new String[56] [4]; String date = getDate(); getData(date, table); printTable(table); } You cannot have anything else in your main method! In other words, you must write the appropriate support methods. getDate is how you should get the date from the user. Then you return the date as a string to the main method. The code will be the same as you have already written many times before, but you are just moving it to a method getData is a method that will read from the data file, select the appropriate data for the table, and put all the data for the table into a 2D array. You must send it the date and a reference to the table array as shown. Note that when you declare the table array in the main method, all of the elements are empty. you pass the table reference to the getDat method, whatever the array argument is in getData, it will refer to the same data array as table. So, you can add data to the 2D array in the getData method and you do not need to return anything back to main. The fact that multiple variable names can refer to the same array is one of the central learning concepts for this assignment. (Hint: Since this method reads from a file, it also can throw a FileNotFoundException.) printTable is a method that pretty-prints the array. After printing the header, it will have to run through the rows and columns and print each element with the appropriate spacing. Give each column 10 spaces and be sure they are left justified as shown in the example runs. getColumn is a method that you have already written for previous assignments. You should reuse it here when you are getting the abbreviation for each state (column 1), the number of cases (column 22), the number of hospitalizations (column 10), and the number of deaths (column 5). It takes the column number as an integer and a whole row as a String, and then returns the data element from the specified column as a String. You will not be calling it from main, so think about which other method should use it. When Example Runs (There would be 56 rows, plus the header row, in each run.) Enter a date (YYYY-MM-DD): 2021-02-12 State Cases Hosp Deaths AK 148 3 2 AL 1097 242 159 AR 565 23 13 0 0 0 AS 11 WI WV WY 1102 467 107 55 0 2 13 0 Enter a date (YYYY-MM-DD): 2020-11-15 State Cases Hosp Deaths 642 7 AL 1979 8 2 AR 2722 35 AK 29 WI 155 6320 867 613 12 8 WV WY