Question: My JavaListApp.java does not produce the following outcome: --jGRASP exec: java EllipsoidListApp Enter file name: Ellipsoid_data_1.txt Ellipsoid Test List Ellipsoid Ex 1 with axes a
My JavaListApp.java does not produce the following outcome: --jGRASP exec: java EllipsoidListApp Enter file name: Ellipsoid_data_1.txt Ellipsoid Test List Ellipsoid "Ex 1" with axes a = 1.0, b = 2.0, c = 3.0 units has: volume = 25.1327 cubic units surface area = 48.9366 square units Ellipsoid "Ex 2" with axes a = 2.3, b = 5.5, c = 7.4 units has: volume = 392.1127 cubic units surface area = 317.9245 square units Ellipsoid "Ex 3" with axes a = 123.4, b = 234.5, c = 345.6 units has: volume = 41,890,963.5508 cubic units surface area = 674,164.7034 square units ----- Summary for Ellipsoid Test List ----- Number of Ellipsoid Objects: 3 Total Volume: 41,891,380.796 cubic units Total Surface Area: 674,531.564 square units Average Volume: 13,963,793.599 cubic units Average Surface Area: 224,843.855 square units ----jGRASP: operation complete. Line # Program output 1 2 3 4 5 6 7 8 9 10 11 12 ----jGRASP exec: java EllipsoidListApp Enter file name: Ellipsoid_data_0.txt Ellipsoid Empty Test List ----- Summary for Ellipsoid Empty Test List ----- Number of Ellipsoid Objects: 0 Total Volume: 0.0 cubic units Total Surface Area: 0.0 square units Average Volume: 0.0 cubic units Average Surface Area: 0.0 square units ----jGRASP: operation complete. Here is my code: import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; /** * Author: Ronald Funes. * Version: 02/21/2023 */ public class EllipsoidListApp { /** * EllipsoidListApp Class. * Param used. * FileNotFoundException. */ public static void main(String[] args) throws FileNotFoundException { // Create a scanner object to get read filename Scanner keyboard = new Scanner(System.in); System.out.print("Enter file name: "); String filename = keyboard.nextLine(); // Close the keyboard keyboard.close(); System.out.println(); //Create a list ArrayList elist = new ArrayList(); // Use scanner to read file Scanner infile = new Scanner(new File(filename)); // Store the name in a local variable String name = infile.nextLine(); //Use while loop to read the lines while (infile.hasNext()) { // add to the list String ename = infile.nextLine(); double a = infile.nextDouble(); double b = infile.nextDouble(); double c = infile.nextDouble(); if (infile.hasNext()) { infile.nextLine(); elist.add(new Ellipsoid(ename, a, b, c)); } } infile.close(); // Create EllipsoidList object EllipsoidList app = new EllipsoidList(name, elist); // print to string System.out.println(app.toString()); System.out.println(); // print summary System.out.println(app.summaryInfo()); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
