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.   PLEASE MAKE THIS PROGRAM SO ALL LENGHTS, HEIGHS AND ARRAY ELEMENTS ARE IN THREE DIGITS AFTER THE DEICIMAL POINT. ALSO, WHEN YOU TYPE BADFILE.TXT IT SHOULD SAY AFER THAT Please enter the file name again or type QUIT to exit:\n THEN YOU TYPE IN THE FILE NAME.  I PROVIDED SCREENSHOTS OF THE FAILED TEST CASES.    Input1.txt 1 2 3 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   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   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   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   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   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   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   Test Case 1       Please enter the file name or type QUIT to exit:\n quitENTER   Test Case 2       Please enter the file name or type QUIT to exit:\n QUITENTER   Test Case 3       Please enter the file name or type QUIT to exit:\n qUiTENTER   Test Case 4       Please enter the file name or type QUIT to exit:\n 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   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   Test Case 11     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 badfile2.txtENTER File: badfile2.txt does not exist.\n Please enter the file name again or type QUIT to exit:\n input3.txtENTER Row 0 Length: 6, Subtotal: 2025.100\n Row 1 Length: 6, Subtotal: 3604.000\n Row 2 Length: 6, Subtotal: 1628.660\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 Column 3 Height: 3, Subtotal: 1568.770\n Column 4 Height: 3, Subtotal: 1801.420\n Column 5 Height: 3, Subtotal: 258.690\n Array Elements: 18, Total: 7257.760\n

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
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.
 
PLEASE MAKE THIS PROGRAM SO ALL LENGHTS, HEIGHS AND ARRAY ELEMENTS ARE IN THREE DIGITS AFTER THE DEICIMAL POINT. ALSO, WHEN YOU TYPE BADFILE.TXT IT SHOULD SAY AFER THAT Please enter the file name again or type QUIT to exit:\n THEN YOU TYPE IN THE FILE NAME.  I PROVIDED SCREENSHOTS OF THE FAILED TEST CASES. 
 
Input1.txt
1 2 3
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
 
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
 
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
 
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
 
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
 
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
 
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
 

Test Case 1

 
 
 
Please enter the file name or type QUIT to exit:\n
quitENTER
 

Test Case 2

 
 
 
Please enter the file name or type QUIT to exit:\n
QUITENTER
 

Test Case 3

 
 
 
Please enter the file name or type QUIT to exit:\n
qUiTENTER
 

Test Case 4

 
 
 
Please enter the file name or type QUIT to exit:\n
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
 

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
 

Test Case 11

 
 
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
badfile2.txtENTER
File: badfile2.txt does not exist.\n
Please enter the file name again or type QUIT to exit:\n
input3.txtENTER
Row 0 Length: 6, Subtotal: 2025.100\n
Row 1 Length: 6, Subtotal: 3604.000\n
Row 2 Length: 6, Subtotal: 1628.660\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
Column 3 Height: 3, Subtotal: 1568.770\n
Column 4 Height: 3, Subtotal: 1801.420\n
Column 5 Height: 3, Subtotal: 258.690\n
Array Elements: 18, Total: 7257.760\n
 
 
Test Case 10 Failed Show what's missing
Please enter the file name or type QUIT to exit: \n
badfile.txt ENTER
File: badfile.txt does not exist.\n
Please enter the file name or type QUIT to exit: \n
input2.txt ENTER
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
Test Case 11 Failed Show what's missing
Please enter the file name or type QUIT to exit: \n
badfile.txt ENTER
File: badfile.txt does not exist.\n
Please enter the file name or type QUIT to exit: \n
badfile2.txt ENTER
File: badfile2.txt does not exist.\n
Please enter the file name or type QUIT to exit: \n
input3.txt ENTER
Row 0 Length: 6, Subtotal: 2025.100 \n
Row 1 Length: 6, Subtotal: 3604.000 \n
Subtotal: 1628.660 \n
Row 2 Length: 6,
Column
Height: 3, Subtotal: 1568.770 \n
Column 1 Height: 3, Subtotal: 1801.420|\n]
Column 2 Height: 3, Subtotal: 258.690\n]
Column 3 Height: 3, Subtotal: 1568.770 \n
Column 4 Height: 3, Subtotal: 1801.420 \n
Column 5 Height: 3, Subtotal: 258.690\n
Array Elements: 18, Total: 7257.760 \n
Test Case 10 Failed
Show what's missing
Please enter the file name or type QUIT to exit: \n
badfile.txt ENTER
File: badfile.txt does not exist.\n
Please enter the file name again or type QUIT to exit: \n
input2.txt ENTER
RowLength: 3, Subtotal: 1012.550 \n
Row 1 Length: 3, Subtotal: 1802.000 \n
Row 2 Length: 3, Subtotal: 814.330 \n
Column 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
Test Case 11 Failed Show what's missing
Please enter the file name or type QUIT to exit: \n
badfile.txt ENTER
File: badfile.txt does not exist.\n
Please enter the file name again or type QUIT to exit: \n
badfile2.txt ENTER
File: badfile2.txt does not exist.\n
Please enter the file name again or type QUIT to exit: \n
input3.txt ENTER
RowLength: 6, Subtotal: 2025.100 \n
Row 1 Length: 6, Subtotal: 3604.000 \n
Row 2 Length: 6, Subtotal: 1628.660 \n
Column Height: 3, Subtotal: 1568.770 \n
Column 1 Height: 3, Subtotal: 1801.420 \n
Column 2 Height: 3, Subtotal: 258.690 \n
Column 3 Height: 3, Subtotal: 1568.770 \n
Column 4 Height: 3, Subtotal: 1801.420 \n
Column 5 Height: 3, Subtotal: 258.690\n
Array Elements: 18, Total: 7257.760 \n
Transcribed Image Text:Test Case 10 Failed Show what's missing Please enter the file name or type QUIT to exit: \n badfile.txt ENTER File: badfile.txt does not exist.\n Please enter the file name or type QUIT to exit: \n input2.txt ENTER 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 Test Case 11 Failed Show what's missing Please enter the file name or type QUIT to exit: \n badfile.txt ENTER File: badfile.txt does not exist.\n Please enter the file name or type QUIT to exit: \n badfile2.txt ENTER File: badfile2.txt does not exist.\n Please enter the file name or type QUIT to exit: \n input3.txt ENTER Row 0 Length: 6, Subtotal: 2025.100 \n Row 1 Length: 6, Subtotal: 3604.000 \n Subtotal: 1628.660 \n Row 2 Length: 6, Column Height: 3, Subtotal: 1568.770 \n Column 1 Height: 3, Subtotal: 1801.420|\n] Column 2 Height: 3, Subtotal: 258.690\n] Column 3 Height: 3, Subtotal: 1568.770 \n Column 4 Height: 3, Subtotal: 1801.420 \n Column 5 Height: 3, Subtotal: 258.690\n Array Elements: 18, Total: 7257.760 \n Test Case 10 Failed Show what's missing Please enter the file name or type QUIT to exit: \n badfile.txt ENTER File: badfile.txt does not exist.\n Please enter the file name again or type QUIT to exit: \n input2.txt ENTER RowLength: 3, Subtotal: 1012.550 \n Row 1 Length: 3, Subtotal: 1802.000 \n Row 2 Length: 3, Subtotal: 814.330 \n Column 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 Test Case 11 Failed Show what's missing Please enter the file name or type QUIT to exit: \n badfile.txt ENTER File: badfile.txt does not exist.\n Please enter the file name again or type QUIT to exit: \n badfile2.txt ENTER File: badfile2.txt does not exist.\n Please enter the file name again or type QUIT to exit: \n input3.txt ENTER RowLength: 6, Subtotal: 2025.100 \n Row 1 Length: 6, Subtotal: 3604.000 \n Row 2 Length: 6, Subtotal: 1628.660 \n Column Height: 3, Subtotal: 1568.770 \n Column 1 Height: 3, Subtotal: 1801.420 \n Column 2 Height: 3, Subtotal: 258.690 \n Column 3 Height: 3, Subtotal: 1568.770 \n Column 4 Height: 3, Subtotal: 1801.420 \n Column 5 Height: 3, Subtotal: 258.690\n Array Elements: 18, Total: 7257.760 \n
Test Case 5 Failed Show what's missing
Please enter the file name or type QUIT to exit: \n
badfile.txt ENTER
File: badfile.txt does not exist.\n
Please enter the file name or type QUIT to exit: \n
quit ENTER
Test Case 6 Failed Show what's missing
Please enter the file name or type QUIT to exit: \n
badfile.txt ENTER
File: badfile.txt does not exist.\n
Please enter the file name or type QUIT to exit: \n
QUIT ENTER
Test Case 7 Failed Show what's missing
Please enter the file name or type QUIT to exit: \n
badfile.txt ENTER
File: badfile.txt does not exist.\n
Please enter the file name or type QUIT to exit: \n
QuIt ENTER
Test Case 5
Failed Show what's missing
Please enter the file name or type QUIT to exit: \n
badfile.txt ENTER
File: badfile.txt does not exist.\n
Please enter the file name again or type QUIT to exit: \n
quit ENTER
Test Case 6
Failed Show what's missing
Please enter the file name or type QUIT to exit: \n
badfile.txt ENTER
File: badfile.txt does not exist.\n
Please enter the file name again or type QUIT to exit: \n]
QUIT ENTER
Test Case 7 Failed Show what's missing
Please enter the file name or type QUIT to exit: \n
badfile.txt ENTER
File: badfile.txt does not exist.\n
Please enter the file name again or type QUIT to exit: \n
QuIt ENTER
Transcribed Image Text:Test Case 5 Failed Show what's missing Please enter the file name or type QUIT to exit: \n badfile.txt ENTER File: badfile.txt does not exist.\n Please enter the file name or type QUIT to exit: \n quit ENTER Test Case 6 Failed Show what's missing Please enter the file name or type QUIT to exit: \n badfile.txt ENTER File: badfile.txt does not exist.\n Please enter the file name or type QUIT to exit: \n QUIT ENTER Test Case 7 Failed Show what's missing Please enter the file name or type QUIT to exit: \n badfile.txt ENTER File: badfile.txt does not exist.\n Please enter the file name or type QUIT to exit: \n QuIt ENTER Test Case 5 Failed Show what's missing Please enter the file name or type QUIT to exit: \n badfile.txt ENTER File: badfile.txt does not exist.\n Please enter the file name again or type QUIT to exit: \n quit ENTER Test Case 6 Failed Show what's missing Please enter the file name or type QUIT to exit: \n badfile.txt ENTER File: badfile.txt does not exist.\n Please enter the file name again or type QUIT to exit: \n] QUIT ENTER Test Case 7 Failed Show what's missing Please enter the file name or type QUIT to exit: \n badfile.txt ENTER File: badfile.txt does not exist.\n Please enter the file name again or type QUIT to exit: \n QuIt ENTER
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 10 images

Blurred answer
Knowledge Booster
Array
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education