Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

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): 159 Enter a date (YYYY-MM-DD): 2021-02-12 State Cases Hosp Deaths AK 148 3 AL 1097 242 AR 565 23 13 AS 0 0 0 AZ 2426 141 172 CA 10059 0 546 CO 2091 48 9 838 0 27 . WI WV WY 1102 467 107 55 0 2 11 13 0 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. When you pass the table reference to the getData 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, 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. 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 AS 0 0 0 WI WV WY 1102 467 107 55 0 2 11 13 0 Enter a date (YYYY-MM-DD): 2020-11-15 State Cases Hosp Deaths AK 642 7 AL 1979 2 AR 2722 29 35 WI WV WY 6320 867 613 155 0 0 12 8 9592 7526 2140 6166 18150 84732 54753 1758 27904 B C D G H K M N o P Q R T U V w Y z AA AB AC date state death deathcon deathIncr deathProk hospitaliz hospitaliz hospitaliz hospitaliz inlcuCum inlcuCurre negative negativelt negativet negativet negativeT on Ventila on Ventila positive positive a positiveln positivesc positiveTe positiveTe positiveTe positiveTe positiveTe recovered to 2 ######## AK 289 0 1243 1243 34 0 1561281 4 55198 0 0 66577 3 ######## AL 2 2066 44767 44767 867 0 2623 1875829 3104 1490 486843 381846 857 0 275245 4 ######## AR 5357 4306 9 1051 14540 14540 577 14 219 2352972 2021 2352972 1500 114 315514 249652 284 0 77315 304460 5 ######## AS 0 0 0 0 0 0 0 6 ######## AZ 15505 13694 25 1811 56946 56946 1598 74 501 2940237 9077 286 807967 753580 1804 0 114497 7 ######## CA 49105 280 7313 0 2073 0 3441946 3441946 6760 0 B ######## CO 5892 5164 5 728 23169 23169 440 13 2135251 4448 334394 420614 398020 802 0 54620 22316 9 ######## CT 7523 0 1357 12257 12257 535 0 6167204 0 273101 256139 0 0 9800 0 #HHHHHHH Dc 995 1 196 0 52 0 28 39648 95 0 28365 1 ######## DE 1367 1236 1 131 175 0 24 531605 687 80291 201 0 88415 2 ######## FL 30434 95 78946 78946 4160 106 9012223 22676 831212 790547 16078849 1834708 1495704 4935 0 165482 155757 2400590 2) 3 ######## GA 16744 14633 2 2111 54753 2778 106 8927 0 985505 804812 0 72085 782965 4 ######## GU 130 0 5 0 2 106994 0 2 7720 7511 4 0 23 248 7528 5 ######## HI 431 431 1 2182 2182 42 0 11 0 7 27174 67 0 26711 6 ######## IA 5336 0 229 0 58 1022903 1262 92673 2342175 27 277268 277268 302 0 58786 17472 55373 300663 309192 7 ######## ID 1826 1607 0 219 6983 6983 142 10 1220 37 493294 926 169150 137430 197 0 91926 22466 20269 40 2197 1468 0 356 16448391 73684 170 1174409 1585 0 9 ######## IN 12372 11947 36 425 42445 42445 870 67 7408 161 2428352 80 655541 881 0 746727 427828 0 ######## KS 4614 0 9071 9071 290 0 2457 82 947591 0 411 34 290832 0 0 6206 -1 ######## KY 4447 4033 21 414 18601 18601 902 46 3883 248 0 148 396997 305543 979 0 9377 35540 242898 46753 2 ######## LA 9466 8798 26 668 756 0 4992511 24668 120 424176 365859 1889 0 396834 3 ######## MA 15826 15508 47 318 19176 19176 927 0 234 4284944 8716 153 569284 539644 1520 0 14895 645482 477796 -4 ######## MD 7715 7533 18 182 34439 34439 973 84 284 2960703 4386 167357 376355 376355 618 0 26456 457509 9606 5 ######## ME 658 643 0 15 1506 1506 75 1 24 1499401 0 14011 1492208 6 43497 34502 130 0 783 9845 40508 12761 C6 ######## MI 0 983 860 0 217 9410432 9410432 107 636269 579919 0 0 734635 529080 27 ######## MN 6432 6162 9 270 25455 25455 282 29 5258 59 2960755 10027 479036 456370 879 0 465382 8 ######## MO 7715 0 1234 0 257 1836185 123655 3862361 178 474997 474997 410 0 23094 79192 524228 -9 ######## MP 2 2 0 4 4 0 17429 0 143 143 8 0 29 0 ######## MS 6553 0 1943 8978 563 0 152 1393383 89 290632 180867 390 0 264456 1 ######## MT 1342 1 4522 4522 78 5 18 953401 3128 11 98779 95500 138 0 95211 2 ######## NC 10926 9683 30 1243 0 402 9188586 43405 842637 737992 2541 0 765456 33 ######## ND 1465 0 3857 3857 40 1 562 8 302885 198 11953 99277 94232 49 0 1442 97114 4 ######## NE 2047 0 6034 163 2 756992 688 2081186 198949 198 0 230666 142336 G5 THHHHHHH NH 1154 1 1093 1093 109 1 339 571296 807 73413 51750 252 0 69319 6 ######## NJ 24 2289 63108 63108 46 434 9566182 0 288 766405 682746 2031 0 Activate Windows 73920 7 ######## NM 3624 14 12916 12916 242 15 2426972 9172 182789 314 0 Go to Settings to activate Windows. 132219 all-states-history-new + 6767 16342 15359 2645 4610 8978 1647 6034 22858 20569 2065 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): 159 Enter a date (YYYY-MM-DD): 2021-02-12 State Cases Hosp Deaths AK 148 3 AL 1097 242 AR 565 23 13 AS 0 0 0 AZ 2426 141 172 CA 10059 0 546 CO 2091 48 9 838 0 27 . WI WV WY 1102 467 107 55 0 2 11 13 0 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. When you pass the table reference to the getData 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, 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. 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 AS 0 0 0 WI WV WY 1102 467 107 55 0 2 11 13 0 Enter a date (YYYY-MM-DD): 2020-11-15 State Cases Hosp Deaths AK 642 7 AL 1979 2 AR 2722 29 35 WI WV WY 6320 867 613 155 0 0 12 8 9592 7526 2140 6166 18150 84732 54753 1758 27904 B C D G H K M N o P Q R T U V w Y z AA AB AC date state death deathcon deathIncr deathProk hospitaliz hospitaliz hospitaliz hospitaliz inlcuCum inlcuCurre negative negativelt negativet negativet negativeT on Ventila on Ventila positive positive a positiveln positivesc positiveTe positiveTe positiveTe positiveTe positiveTe recovered to 2 ######## AK 289 0 1243 1243 34 0 1561281 4 55198 0 0 66577 3 ######## AL 2 2066 44767 44767 867 0 2623 1875829 3104 1490 486843 381846 857 0 275245 4 ######## AR 5357 4306 9 1051 14540 14540 577 14 219 2352972 2021 2352972 1500 114 315514 249652 284 0 77315 304460 5 ######## AS 0 0 0 0 0 0 0 6 ######## AZ 15505 13694 25 1811 56946 56946 1598 74 501 2940237 9077 286 807967 753580 1804 0 114497 7 ######## CA 49105 280 7313 0 2073 0 3441946 3441946 6760 0 B ######## CO 5892 5164 5 728 23169 23169 440 13 2135251 4448 334394 420614 398020 802 0 54620 22316 9 ######## CT 7523 0 1357 12257 12257 535 0 6167204 0 273101 256139 0 0 9800 0 #HHHHHHH Dc 995 1 196 0 52 0 28 39648 95 0 28365 1 ######## DE 1367 1236 1 131 175 0 24 531605 687 80291 201 0 88415 2 ######## FL 30434 95 78946 78946 4160 106 9012223 22676 831212 790547 16078849 1834708 1495704 4935 0 165482 155757 2400590 2) 3 ######## GA 16744 14633 2 2111 54753 2778 106 8927 0 985505 804812 0 72085 782965 4 ######## GU 130 0 5 0 2 106994 0 2 7720 7511 4 0 23 248 7528 5 ######## HI 431 431 1 2182 2182 42 0 11 0 7 27174 67 0 26711 6 ######## IA 5336 0 229 0 58 1022903 1262 92673 2342175 27 277268 277268 302 0 58786 17472 55373 300663 309192 7 ######## ID 1826 1607 0 219 6983 6983 142 10 1220 37 493294 926 169150 137430 197 0 91926 22466 20269 40 2197 1468 0 356 16448391 73684 170 1174409 1585 0 9 ######## IN 12372 11947 36 425 42445 42445 870 67 7408 161 2428352 80 655541 881 0 746727 427828 0 ######## KS 4614 0 9071 9071 290 0 2457 82 947591 0 411 34 290832 0 0 6206 -1 ######## KY 4447 4033 21 414 18601 18601 902 46 3883 248 0 148 396997 305543 979 0 9377 35540 242898 46753 2 ######## LA 9466 8798 26 668 756 0 4992511 24668 120 424176 365859 1889 0 396834 3 ######## MA 15826 15508 47 318 19176 19176 927 0 234 4284944 8716 153 569284 539644 1520 0 14895 645482 477796 -4 ######## MD 7715 7533 18 182 34439 34439 973 84 284 2960703 4386 167357 376355 376355 618 0 26456 457509 9606 5 ######## ME 658 643 0 15 1506 1506 75 1 24 1499401 0 14011 1492208 6 43497 34502 130 0 783 9845 40508 12761 C6 ######## MI 0 983 860 0 217 9410432 9410432 107 636269 579919 0 0 734635 529080 27 ######## MN 6432 6162 9 270 25455 25455 282 29 5258 59 2960755 10027 479036 456370 879 0 465382 8 ######## MO 7715 0 1234 0 257 1836185 123655 3862361 178 474997 474997 410 0 23094 79192 524228 -9 ######## MP 2 2 0 4 4 0 17429 0 143 143 8 0 29 0 ######## MS 6553 0 1943 8978 563 0 152 1393383 89 290632 180867 390 0 264456 1 ######## MT 1342 1 4522 4522 78 5 18 953401 3128 11 98779 95500 138 0 95211 2 ######## NC 10926 9683 30 1243 0 402 9188586 43405 842637 737992 2541 0 765456 33 ######## ND 1465 0 3857 3857 40 1 562 8 302885 198 11953 99277 94232 49 0 1442 97114 4 ######## NE 2047 0 6034 163 2 756992 688 2081186 198949 198 0 230666 142336 G5 THHHHHHH NH 1154 1 1093 1093 109 1 339 571296 807 73413 51750 252 0 69319 6 ######## NJ 24 2289 63108 63108 46 434 9566182 0 288 766405 682746 2031 0 Activate Windows 73920 7 ######## NM 3624 14 12916 12916 242 15 2426972 9172 182789 314 0 Go to Settings to activate Windows. 132219 all-states-history-new + 6767 16342 15359 2645 4610 8978 1647 6034 22858 20569 2065

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

Recommended Textbook for

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 1 Lncs 8055

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013 Edition

3642402844, 978-3642402845

More Books

Students also viewed these Databases questions

Question

What steps should be taken to address any undesirable phenomena?

Answered: 1 week ago