Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This assignment will require information from lectures and zyBooks chapters on Branches, Loops, and Arrays. Create a new Eclipse project called firstlastL02, with first as

This assignment will require information from lectures and zyBooks chapters on Branches, Loops, and Arrays.

Create a new Eclipse project called firstlastL02, with first as your first name and last as your last name, e.g., jasonpowellL02.

In the project, create a folder called files. This folder must be in the project but not within the src folder. Place the data files (values.txt and numbers.txt) in the files folder. If dragging and dropping it in Eclipse, remember to select Copy files, not Link to files.

The data files have integers like the example below from values.txt. The first value (shown in blue) is the number of rows for the jagged 2D array that will store the values. The first value in each row (red) is the number of values for that row. The remaining values in the row are the values you store in that row of the array.

4

9 -18 -44 -57 9 36 20 -35 -87 -100

4 19 75 -68 10

2 74 70

7 1 79 -5 -40 41 43 15

Create a Java class called Driver in the arrays package. This class will contain your main method that accomplishes the following tasks.

Prompt the user for the file name. e.g.:

Enter the filename: values.txt

Create File and Scanner variables to use the data file in the files folder. You may also need additional variables for the program.

Declare and instantiate a two-dimensional jagged array. To do this, you will need to read the first integer value in the data file, which will be the number of rows in your jagged array.

You read the data file into the jagged array using nested for loops. Within the loops, you must:

Instantiate the row of the jagged array before reading in the values for that row

Read in the values for the row one at a time, placing it within the jagged array row elements

Use the array length variable in the loops

Use nested for loops

Remember to close the scanner after reading all the values

Using nested while loops, you display the jagged array contents, formatting them like the one below. You must:

Use nested while loops

Use the array length variable in the loops

[-18, -44, -57, 9, 36, 20, -35, -87, -100]

[19, 75, -68, 10]

[74, 70]

[1, 79, -5, -40, 41, 43, 15]

Using nested do-while loops, you are to calculate the average value of the numbers in the jagged array. You must:

Use nested do-while loop to accumulate the values

Use the array length variable in the loops

Get the total count of values by using the array length variable

Output the average to three decimal places using printf

Average: 1.727

The complete output for values.txt is below. You must write your program to use any data file, including numbers.txt, and you can assume that I will use correctly formatted files.

Enter the filename: values.txt

[-18, -44, -57, 9, 36, 20, -35, -87, -100]

[19, 75, -68, 10]

[74, 70]

[1, 79, -5, -40, 41, 43, 15]

Average: 1.727

When complete, zip the entire Eclipse project like in Zipping Eclipse Projects for Submission in the Resources Module in Moodle, then upload the zipped project. Please note that the whole project must be zipped and submitted so that I can import it directly into Eclipse. I will not recreate your project, copy-and-paste code, or move files around, to make your project work because you submitted it incorrectly.

Warning: Always check to ensure you have submitted the correct zipped project by returning to the submission location and reviewing it. Please note that you may not resubmit the assignment because you forgot to submit something or submitted incorrect files.

Numbers.txt:

20 19 46 6 -48 56 -37 1 43 -12 -79 34 80 -1 -68 -59 89 -29 55 -14 -65 9 24 60 94 98 -40 -81 77 -56 -38 13 -16 -15 -1 79 92 35 -34 -80 51 -94 -24 19 45 4 72 -48 -67 97 15 -99 -60 -43 43 80 -41 67 -58 51 68 71 -35 80 29 -99 25 -67 2 -26 13 -99 8 -65 -7 -99 47 77 -74 14 75 -76 -63 -99 67 -75 83 61 62 26 47 59 17 -8 -5 -49 -54 -29 -39 -57 -74 29 43 -18 60 77 -39 22 86 12 21 -21 -72 18 -74 -59 51 -56 73 -40 -41 -71 -65 89 -85 -63 -57 -68 -55 -31 22 84 15 83 50 -67 48 87 34 -91 89 28 -90 33 78 -32 98 -30 18 -57 -49 -18 71 9 -67 55 27 -82 -89 -41 -51 13 94 32 -88 -12 79 4 -12 97 -42 -84 25 -40 -28 4 93 -98 -44 69 -25 54 76 -85 57 -100 65 -86 68 -62 -4 36 47 -40 -95 62 -23 -86 23 -9 -10 75 81 44 88 -19 75 19 67 -97 82 -76 -83 3 -39 53 13 -65 9 19 41 35 24 -41 82 66 -5 17 14 -99 -13 47 -62 -34 -83 35 -82 34 50 96 -61 78 -64 49 -65 -50 -3 11 49 -8 -38 11 3 59 45 72 24 17 -84 9 82 29 50 88 -4 38 77 -63 -82 23 60 -13 77 72 -14 -26 -51 22 45 55 76 73 71 40 -41 75 -29 -97 84 86 -72 -28 -56 10 87 65 64 37 -93 65 -24 -89 -61 4 16 11 12 34 -88 34 -81 -33 39 -56 -41 17 70 0 -99 68 -60 22 -47 93 14 -88 -90 87 -74 45 93 29 -17 12 29 -10 6 -40 35 24 10 48 40 55

values.txt:

4 9 -18 -44 -57 9 36 20 -35 -87 -100 4 19 75 -68 10 2 74 70 7 1 79 -5 -40 41 43 15

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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