
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
JAVA PROGRAM
Chapter 7. PC #16. 2D Array Operations with Additional Requirements
Write a program that creates an ArrayList of ArrayList of Doubles. The program should ask the user to enter the filename from the keyboard and validate the file for existence. Once the file is verified, the program should load the two-dimensional ArrayList with test data from the file. Be careful, as some of the files will contain rows with different number of elements. The program should work regardless whether the input data is perfectly rectangular or ragged. The program should have the following methods:
• main. Main entry point for the program.
• getRowSubtotal. This method should accept a two-dimensional ArrayList as its first argument and an integer as its second argument. The second argument should be the index of the row in the ArrayList. The method should return the subtotal of the values in the specified row.
• getColSubtotal. This method should accept a two-dimensional ArrayList as its first argument and an integer as its second argument. The second argument should be the index of the column in the ArrayList. The method should return the subtotal of the values in the specified column. If any of the rows has a size that is less than the column number, then that row should be skipped when calculating the column subtotal.
• getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in the array.
Demonstrate each of the methods in this program.
Input1.txt
1 2 3
4 5 6
7 8 9
4 5 6
7 8 9
Input2.txt
555.66 333.44 123.45
778.88 900.00 123.12
234.23 567.98 12.12
778.88 900.00 123.12
234.23 567.98 12.12
Input3.txt
555.66 333.44 123.45 555.66 333.44 123.45
778.88 900.00 123.12 778.88 900.00 123.12
234.23 567.98 12.12 234.23 567.98 12.12
778.88 900.00 123.12 778.88 900.00 123.12
234.23 567.98 12.12 234.23 567.98 12.12
Input4.txt
555.66 333.44 123.45
778.88 900.00 123.12
234.23 567.98 12.12
555.66 333.44 123.45
778.88 900.00 123.12
234.23 567.98 12.12
555.66 333.44 123.45
778.88 900.00 123.12
234.23 567.98 12.12
778.88 900.00 123.12
234.23 567.98 12.12
555.66 333.44 123.45
778.88 900.00 123.12
234.23 567.98 12.12
555.66 333.44 123.45
778.88 900.00 123.12
234.23 567.98 12.12
Input5.txt
555.66 333.44 123.45 555.66 333.44 123.45
778.88 900.00 123.12 778.88 900.00
234.23 567.98 12.12 234.23
778.88 900.00 123.12 778.88 900.00
234.23 567.98 12.12 234.23
Input6.txt
555.66 333.44 123.45 555.66
778.88 900.00 123.12 778.88 900.00
234.23 567.98 12.12 234.23 567.98 12.12
778.88 900.00 123.12 778.88 900.00
234.23 567.98 12.12 234.23 567.98 12.12
Input7.txt
555.66 333.44 123.45 755.23
778.88 900.00 123.12
234.23 567.98
555.66
778.88 900.00 123.12 999.99
234.23 567.98 12.12
555.66 333.44
778.88
234.23 567.98 12.12 987.65 432.11
820.17
778.88 900.00 123.12
234.23 567.98
555.66
778.88 900.00 123.12 999.99
234.23 567.98 12.12
555.66 333.44
778.88
234.23 567.98 12.12 987.65 432.11
820.17
Input8.txt
555.66
778.88 900.00
234.23 567.98 333.44
555.66 123.45 755.23 888.88
778.88 900.00 123.12 999.99 777.77
778.88 900.00 123.12 999.99 777.77 666.66
778.88 900.00 123.12 999.99 777.77 555.55 444.44
778.88 900.00 123.12 999.99 777.77 333.33 222.22 111.11
778.88 900.00
234.23 567.98 333.44
555.66 123.45 755.23 888.88
778.88 900.00 123.12 999.99 777.77
778.88 900.00 123.12 999.99 777.77 666.66
778.88 900.00 123.12 999.99 777.77 555.55 444.44
778.88 900.00 123.12 999.99 777.77 333.33 222.22 111.11
est Case 1
Please enter the file name or type QUIT to exit:\n
quitENTER
quitENTER
Test Case 2
Please enter the file name or type QUIT to exit:\n
QUITENTER
QUITENTER
Test Case 3
Please enter the file name or type QUIT to exit:\n
qUiTENTER
qUiTENTER
Test Case 4
Please enter the file name or type QUIT to exit:\n
QuItENTER
QuItENTER
Test Case 5
Please enter the file name or type QUIT to exit:\n
badfile.txtENTER
File: badfile.txt does not exist.\n
Please enter the file name again or type QUIT to exit:\n
quitENTER
badfile.txtENTER
File: badfile.txt does not exist.\n
Please enter the file name again or type QUIT to exit:\n
quitENTER
Test Case 6
Please enter the file name or type QUIT to exit:\n
badfile.txtENTER
File: badfile.txt does not exist.\n
Please enter the file name again or type QUIT to exit:\n
QUITENTER
badfile.txtENTER
File: badfile.txt does not exist.\n
Please enter the file name again or type QUIT to exit:\n
QUITENTER
Test Case 7
Please enter the file name or type QUIT to exit:\n
badfile.txtENTER
File: badfile.txt does not exist.\n
Please enter the file name again or type QUIT to exit:\n
QuItENTER
badfile.txtENTER
File: badfile.txt does not exist.\n
Please enter the file name again or type QUIT to exit:\n
QuItENTER
Test Case 8
Please enter the file name or type QUIT to exit:\n
badfile.txtENTER
File: badfile.txt does not exist.\n
Please enter the file name again or type QUIT to exit:\n
qUiTENTER
badfile.txtENTER
File: badfile.txt does not exist.\n
Please enter the file name again or type QUIT to exit:\n
qUiTENTER
Test Case 9
Please enter the file name or type QUIT to exit:\n
input1.txtENTER
Row 0 Length: 3, Subtotal: 6.000\n
Row 1 Length: 3, Subtotal: 15.000\n
Row 2 Length: 3, Subtotal: 24.000\n
Column 0 Height: 3, Subtotal: 12.000\n
Column 1 Height: 3, Subtotal: 15.000\n
Column 2 Height: 3, Subtotal: 18.000\n
Array Elements: 9, Total: 45.000\n
input1.txtENTER
Row 0 Length: 3, Subtotal: 6.000\n
Row 1 Length: 3, Subtotal: 15.000\n
Row 2 Length: 3, Subtotal: 24.000\n
Column 0 Height: 3, Subtotal: 12.000\n
Column 1 Height: 3, Subtotal: 15.000\n
Column 2 Height: 3, Subtotal: 18.000\n
Array Elements: 9, Total: 45.000\n
Test Case 10
Please enter the file name or type QUIT to exit:\n
badfile.txtENTER
File: badfile.txt does not exist.\n
Please enter the file name again or type QUIT to exit:\n
input2.txtENTER
Row 0 Length: 3, Subtotal: 1012.550\n
Row 1 Length: 3, Subtotal: 1802.000\n
Row 2 Length: 3, Subtotal: 814.330\n
Column 0 Height: 3, Subtotal: 1568.770\n
Column 1 Height: 3, Subtotal: 1801.420\n
Column 2 Height: 3, Subtotal: 258.690\n
Array Elements: 9, Total: 3628.880\n
badfile.txtENTER
File: badfile.txt does not exist.\n
Please enter the file name again or type QUIT to exit:\n
input2.txtENTER
Row 0 Length: 3, Subtotal: 1012.550\n
Row 1 Length: 3, Subtotal: 1802.000\n
Row 2 Length: 3, Subtotal: 814.330\n
Column 0 Height: 3, Subtotal: 1568.770\n
Column 1 Height: 3, Subtotal: 1801.420\n
Column 2 Height: 3, Subtotal: 258.690\n
Array Elements: 9, Total: 3628.880\n

Transcribed Image Text:Test Case 14
Please enter the file name or type QUIT to exit:
input6.txt ENTER
RowLength: 4, Subtotal: 1568.210
Row 1 Length: 5, Subtotal: 3480.880
Row 2 Length: 6, Subtotal: 1628.660
Column Height: 3, Subtotal: 1568.770 n
Column 1 Height: 3, Subtotal: 1801.420
Column 2 Height: 3, Subtotal: 258.690
Column 3 Height: 3, Subtotal: 1568.770
Column 4 Height: 2, Subtotal: 1467.980
Column 5 Height: 1, Subtotal: 12.120
Array Elements: 15, Total: 6677.750
Test Case 15
Please enter the file name or type QUIT to exit:
input7.txt ENTER
RowLength: 4, Subtotal: 1767.780 n
Row 1 Length: 3, Subtotal: 1802.000 n
Row 2 Length: 2, Subtotal: 802.210
Row 3 Length: 1, Subtotal: 555.660n
Row 4 Length: 4, Subtotal: 2801.990
Row 5 Length: 3, Subtotal: 814.330
Row 6 Length: 2, Subtotal: 889.100
Row 7 Length: 1, Subtotal: 778.880
Row 8 Length: 5, Subtotal: 2234.090
820.170
Column Height: 10, Subtotal: 5526.480
Row 9 Length: 1, Subtotal:
0
Column 1 Height: 7, Subtotal: 4170.820
Column 2 Height: 5, Subtotal: 393.930 \
Column 3 Height: 3, Subtotal: 2742.870 n
Column 4 Height: 1, Subtotal: 432.110
Array Elements: 26, Total: 13266.210
Test Case 16
Please enter the file name or type QUIT to exit:
input8.txt ENTER
RowLength: 1, Subtotal: 555.660
Row 1 Length: 2, Subtotal: 1678.880
Row 2 Length: 3, Subtotal: 1135.650
Row 3 Length: 4, Subtotal: 2323.220
Row 4 Length: 5, Subtotal: 3579.760
Row 5 Length: 6, Subtotal: 4246.420
Row 6 Length: 7, Subtotal: 4579.750
Row 7 Length: 8, Subtotal: 4246.420 n
Column Height: 8, Subtotal: 5239.950
Column 1 Height: 7, Subtotal: 5191.430
Column 2 Height: 6, Subtotal: 1581.150
Column 3 Height: 5, Subtotal: 4888.840
Column 4 Height: 4, Subtotal: 3111.080
Column 5 Height: 3, Subtotal: 1555.540
Column 6 Height: 2, Subtotal: 666.660
Column 7 Height: 1, Subtotal: 111.110
Array Elements: 36, Total: 22345.760

Transcribed Image Text:Test Case 11
Please enter the file name or type QUIT to exit: n
badfile.txt ENTER
File: badfile.txt does not exist.
Please enter the file name again or type QUIT to exit:
badfile2.txt ENTER
File: badfile2.txt does not exist.
Please enter the file name again or type QUIT to exit:
input3, txt
.txt ENTER
RowLength: 6, Subtotal: 2025.100 \n
Row 1 Length: 6, Subtotal: 3604.000
Row 2 Length: 6, Subtotal: 1628.660
.000 n
Column Height: 3, Subtotal: 1568.770
Column 1 Height: 3, Subtotal: 1801.420 n
Column 2 Height: 3, Subtotal: 258.690
Column 3 Height: 3, Subtotal: 1568.7705
Column 4 Height: 3, Subtotal: 1801.420
Column 5 Height: 3, Subtotal: 258.690
Array Elements: 18, Total: 7257.760
Test Case 12
Please enter the file name or type QUIT to exit:
badfile.txt ENTER
File: badfile.txt does not exist.
Please enter the file name again or type QUIT to exit: M
badfile2.txt ENTER
File: badfile2.txt does not exist.n
Tato
Please enter the file name again or type QUIT to exit: M
2002
badfile3.txt ENTER
PAVA
File: badfile3.txt does not exist. n
Please enter the file name again or type QUIT to exit:
tut
input4.txt ENTER
Row
Length: 3, Subtotal: 1012.550
Row 1 1 Length: 3, Subtotal: 1802.000
Row 2 Length: 3, Subtotal: 814.330
Row 3 Length: 3, Subtotal: 1012.550
Row 4 Length: 3, Subtotal: 1802.000
Row 5 Length: 3, Subtotal: 814.330[
Row 6 Length: 3, Subtotal: 1012.550
Row 7 Length: 3,
3,
Subtotal: 1802.000
02.0000
Row 8 Length: 3, Subtotal: 814.330
Column Height: 9, Subtotal: 4706.310n
Column 1 Height: 9, Subtotal: 5404.260
Column 2 Height: 9, Subtotal: 776.070
Array Elements: 27, Total: 10886.640
Test Case 13
Please enter the file name or type QUIT to exit:
badfile.txt ENTER
File: badfile.txt does not exist.\n
Please enter the file name again or type QUIT to exit: m
badfile2.txt ENTER
Dagr
File: badfile2.txt does not exist.\n
A
Please enter the file name again or type QUIT to exit:
con ene
badfile3.txt [ENTER
e badle tv
File: badfile3.txt does not exist.\n
A
Please enter the file name again or type QUIT to exit:
2002
badfile4.txt ENTER
File: badfile4.txt does not exist.
Please enter the file name again or type QUIT to exit:
inputs.txt
tyt [ENTER
ENTER
RowLength: 6, Subtotal: 2025.100 m
Row 1 Length: 5, Subtotal: 3480.880
Row 2 Length: 4, Subtotal: 1848.560
Height: 3, Subtotal: 1568.770
Column
Column 1 Height: 3, Subtotal: 1801.420 n
Column 2 Height: 3, Subtotal: 258.69€
Column 3 Height: 3, Subtotal: 1568.770
Column 4 Height: 2, Subtotal: 1233.440
Column 5 Height: 1, Subtotal: 123.450
Array Elements: 15, Total: 6554.540
Test Case 14
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- JAVA PROGRAM Chapter 7. PC #16. 2D Array Operations Write a program that creates a two-dimensional array initialized with test data. Use any primitive data type that you wish. The program should have the following methods: • getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in the array. • getAverage. This method should accept a two-dimensional array as its argument and return the average of all the values in the array. • getRowTotal. This method should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The method should return the total of the values in the specified row. • getColumnTotal. This method should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a column in the array. The method should return the…arrow_forwardIn visual basic Write the code that will sequentially search through the array strFirstNames and will print out the word "Found" if the name "Brian" is in the array.arrow_forwardComputer Science JAVA #7 - program that reads the file named randomPeople.txt sort all the names alphabetically by last name write all the unique names to a file named namesList.txt , there should be no repeatsarrow_forward
- 1- Arrays can be created to store values of multiple data types at one place. True False 2- To copy the contents of one array to another you must copy the individual array elements. True Falsearrow_forward# Declare a named constant for array size here. MAX_AVERAGES = 8 # Declare array here. # Write a loop to get batting averages from user and assign to array. averageString = input("Enter a batting average: ") battingAverage = float(averageString) # Assign value to array. # Assign the first element in the array to be the minimum and the maximum. minAverage = averages[0] maxAverage = averages[0] # Start out your total with the value of the first element in the array. total = averages[0] # Write a loop here to access array values starting with averages[1] # Within the loop test for minimum and maximum batting averages. # Also accumulate a total of all batting averages. # Calculate the average of the 8 batting averages. # Print the batting averages stored in the averages array. # Print the maximum batting average, minimum batting average, and average batting average. This is on mindtap pyton what needs to be fixarrow_forwardCan you fix the code please on the first picture shows the error output. // Corrected code #define _CRT_SECURE_NO_WARNINGS #include "LibraryManagement.h" #include "Books.h" #include "DigitalMedia.h" #include "LibraryConfig.h" #include #include #include #include // Include the necessary header for boolean data type // Comparison function for qsort to sort Digital Media by ID int compareDigitalMedia(const void* a, const void* b) { return ((struct DigitalMedia*)a)->id - ((struct DigitalMedia*)b)->id; } // initializing library struct Library initializeLibrary() { struct Library lib; lib.bookCount = 0; lib.ebookCount = 0; lib.digitalMediaCount = 0; // Initialize book array for (int i = 0; i < MAX_BOOK_COUNT; i++) { lib.books[i].commonAttributes.id = -1; // Set an invalid ID to mark empty slot } // Initialize ebook array for (int i = 0; i < MAX_EBOOK_COUNT; i++) { lib.ebooks[i].commonAttributes.id = -1; }…arrow_forward
- Find primes This program creates and displays a 5x10 matrix(5 rows and 10 columns) of random integers between 1 and a maximum value(user input). Hint: Use the random library to generate each number and place it into your 2D list. The program then counts the number of prime numbers in each row of the array and displays this number, along with the found primes. The program finally displays the total number of prime numbers in the matrix.arrow_forwardProblem Description - JAVA PROGRAMMING Use a Two-dimensional (3x3) array to solve the following problem: Write an application that inputs nine numbers, each of which is between 1 and 10, inclusive. Display the array after the user inputs each value. Rotate/flip the array by changing places. Make the rows columns and vice versa. You have to move the elements to their new locations. Remember to validate the input and display an error message if the user inputs invalid data. Documentation and the screenshot(s) of the results. Example: 1 2 3 4 5 6 7 8 9 the result will be : 1 4 7 2 5 8 3 6 9arrow_forwardAlphabet Random Walk• Write a program to generate a random walk that spans a 10*10 character array (The initial values of the elements are all.). The program must randomly walk from one element to another, moving one element position up, down, left or right each time. The elements that have been visited are labeled with the letters A through Z in the order in which they were visitedarrow_forward
- Write the statement that declares and instantiates an array of type double using the identifier temperatures that will hold 30 values. Edit View Insert Format Tools Table 12pt v Paragraph v :arrow_forwardA file USPopulation.txt contains the population of the US starting in year 1950 and then each subsequent record has the population for the following year. USPopulation.txtDownload USPopulation.txt Write a program that uses an array with the file that displays these in a menu and then produces the results. This is not an Object Oriented Program but should be a procedural program, calling methods to do the following: 1: Displays the year and the population during that year 2. The average population during that time period (Add up the populations of all records and divide by the number of years). 3. The year with the greatest increase in population - print the year and that population and that amount. To figure this out, compare the difference in population before of say year 1950 and 1951, store that difference somewhere. Compare 1951 with 1952, find that difference. Is that difference greater than the stored difference? If so, move that the the maximum place. 4.…arrow_forward2DArray method:It will allocate a block of memory which represents a two-dimension arraybased on the input values supplied by the user. Ask the user to enter the number of rows andcolumn for 2D array that the user want to manipulate. The number of rows and columns that theuser enters may or may not define a square matrix (when the number of rows equals the numberof columns). The array will have exactly rows time columns (m * n) elements. It will notcontain any extra or empty cells. Initialize the “matrix” by rows with random number between 1to 100. Pass two arguments by out reference so that you can assign the number of row andcolumns of data to the first and second arguments. This is return 2D array method afterallocating new memory for 2D array and initialize it with random value. Generate randomnumber code in C# as following: Random randnum = new Random( );int number = randnum.Next (1, 101);SwapRow method: it will rotate the data in the matrix in an up/down method such that the…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education