Question
Need help trying to use switch statement but cant figure it out how to move variables *********************************Ellipsoid.java******************************************** import java.text.DecimalFormat; /**. * * * @author *
Need help trying to use switch statement but cant figure it out how to move variables
*********************************Ellipsoid.java********************************************
import java.text.DecimalFormat;
/**. * * * @author * @version */ public class Ellipsoid { //Fields private String label = ""; private double a = 0; private double b = 0; private double c = 0;
//constructor /**. * @param labelIn establish the label * @param aIn establishes a axes. * @param bIn establishes b axes. * @param cIn establishes c axes. */ public Ellipsoid(String labelIn, double aIn, double bIn, double cIn) { setLabel(labelIn); setA(aIn); setB(bIn); setC(cIn); }
//Methods /**. * @return getLabel */ public String getLabel() { return label; }
/**. * * @param labelIn this retrieves a label. * @return setLabel */ public boolean setLabel(String labelIn) { if (labelIn == null) { return false; } else { label = labelIn.trim(); return true; } }
/**. * * @return getA */ public double getA() { return a; }
/**. * * @param aIn this returms a boolean. * @return setA */ public boolean setA(double aIn) { if (aIn > 0) { a = aIn; return true; } else { return false; } }
/**. * * @return getB */ public double getB() { return b; }
/**. * * @param bIn this returms a boolean. * @return setB */ public boolean setB(double bIn) { if (bIn > 0) { b = bIn; return true; } else { return false; } }
/**. * * @return getC */ public double getC() { return c; }
/**. * * @param cIn this returna a boolean. * @return setC */ public boolean setC(double cIn) { if (cIn > 0) { c = cIn; return true; } else { return false; } }
/**. * * @return volume */ public double volume() { double volume = ((4 * Math.PI * a * b * c) / 3); return volume; }
/**. * * @return surfaceArea */ public double surfaceArea() { double thePowers = (Math.pow((a * b), 1.6) + Math.pow((a * c), 1.6) + Math.pow((b * c), 1.6)) / 3; double surfaceArea = 4 * Math.PI * Math.pow(thePowers, (1.0 / 1.6)); return surfaceArea; } /**. * * @return toString */ public String toString() { DecimalFormat decimalFormat = new DecimalFormat("#,##0.0###"); return "Ellipsoid \"" + getLabel() + "\" with axes a = " + decimalFormat.format(a) + ", b = " + decimalFormat.format(b) + ", c = " + decimalFormat.format(c) + " units has: \tvolume = " + decimalFormat.format(volume()) + " cubic units" + " \tsurface area = " + decimalFormat.format(surfaceArea()) + " square units"; } }
*********************************EllipsoidList.java********************************************
import java.text.DecimalFormat; import java.util.ArrayList; /**. * * * @author * @version */ public class EllipsoidList { private String list; private ArrayList
/** * Create a TriangleList object. constructor. * * @param listIn for listName * @param ellipsoidListIn for ellipsoidList */ public EllipsoidList(String listIn, ArrayList
//methods /**. * @return the list name */ public String getName() { return list; //// }
/**. * @return the list name */ public int numberOfEllipsoids() { return ellipsoidList.size(); }
/**. * @return the list name */ public double totalVolume() { double total = 0; //use for each loop for (Ellipsoid e : ellipsoidList) { if (e != null) { total += (e.volume()); } } // return the total volume return total; }
/** * counts the total. * * @return totalSurfaceArea */ public double totalSurfaceArea() { double total = 0; //use for each loop for (Ellipsoid e : ellipsoidList) { if (e != null) { total += (e.surfaceArea()); } } return total; }
/** * finds. * * @return averageVolume */ public double averageVolume() { if (this.numberOfEllipsoids() == 0) { return 0; } else { return this.totalVolume() / this.numberOfEllipsoids(); } }
/** * finds. * * @return averageSurfaceArea */ public double averageSurfaceArea() { if (this.numberOfEllipsoids() == 0) { return 0; } else { return this.totalSurfaceArea() / this.numberOfEllipsoids(); } }
/** * gets a summary of the ellipsoid in the list. * * @return summaryInfo */ public String toString() { String result = getName() + " "; int index = 0; while (index
/** * gets a summary of the ellipsoid in the list. * * @return summaryInfo */
public String summaryInfo() { DecimalFormat decFt = new DecimalFormat("#,##0.###"); String result = ""; result += " "; result += "---- Summary for " + getName() + "----"; result += " Number of Ellipsoid Objects: " + numberOfEllipsoids(); result += " Total Volume: " + decFt.format(totalVolume()) + " cubic units"; result += " Total Surface Area: " + decFt.format(totalSurfaceArea()) + " square units"; result += " Average Volume: " + decFt.format(averageVolume()) + " cubic units"; result += " Average Surface Area: " + decFt.format(averageSurfaceArea()) + " square units"; return result; } /**. * * * @return ellipsoidList * */ public ArrayList
Project: Ellipoid List Menu App Page 5 of 10 o summaryinfo: Returns a String (does not begin with in) containing the name of the list (which can change depending of the value read from the file) followed by various summary items: number of Ellipsoid objects. total volume, total surface area, average volume. and average surface area. Use "4.440.044" as the pattern to fornat the double valucs. For an example, in the previous project scelincs 18 through 24 in the output below from EllipsoidListApp for the Ellipsoid_dara_lour input file. The second example below shows the output from Ellipsoid ListApp for the Ellipsoid dala 0.124 input filc which contains a list name but no Ellipsoid data. 0 The following six methods are new in Project 6: o getList: Returns thc ArrayList of Ellipsoid objects (the second field above). reactile: Takes a String parameter representing the file name, reads in the file, storing the list naine and creating an ArrayList of Ellipsoid objects, uses the list name and the ArrayList to create an Ellipsoid List object, and then returns the Ellipsoid List object. See note # 1 under Important Considerations for the EllipsoidList Menu App class (last page) to see how this method should be called o addEllipsoid: Returns nothing but takes four parameters (label. a, b, and c). creates a new Ellipsoid objcct, and adds it to the Ellipsoid List objcct (1.c., adds illo the ArrayList of Ellipsoid objects in the Ellipsoid List object). o findzllipscid: Takes a label of an Ellipsoid as the String parameter and returns the corresponding Ellipsoid object if found in the Ellipsoid List object: otherwise returns null. Casc should be ignored when allcmpting to malch the label. deletezllipsoid: Takes a String as a parameter that represents the label of the Ellipsoid and returns the Ellipsoid if it is found in the Ellipsoid List object and deleted; otherwise retums null. Case should be ignored when attempting to match the label; consider calling using firdEllipsoid in this method. editzllipsoid: Takes four parameters (label, a, b, and c), uses the label to find the corresponding the Ellipsoid object. If found, sets the a, b, and c to the values passed in as parameters, and returns the Ellipsoid object. If not found, returns null. This method should not change the label. Code and Test: Remember to import java.util.ArrayList, java.util.Scanner, java.io.File, java.io.FileNotFoundException. These classes will be needed in the readFile method which will require a throws clause for FileNotFoundException. Some of the methods above require that you use a loop to yo through the objects in thc ArrayList. You may want to implement the class below in parallel with this one to facilitatc testing. That is, after implementing one to the methods above, you can implement the corresponding "case" in the switch for menu described below in the EllipsoidListMenu App class. Page 5 of 10 Project: Ellipoid List Menu App Page 6 of 10 EllipsoidListMenuApp.java (replaces EllipsoidListApp class from the previous project) Requirements: Create an EllipsoidListMenuApp class with a main method that presents the user with a menu with cight options, cach of which is implemented lo do the following: (1) read the input file and create an Ellipsoid List object, (2) print the Ellipsoid List objcct3) print the summary for the EllipsoidList object. (4) add an Ellipsoid object to the Ellipsoid List object. (5) delete an Ellipsoid object from the EllipsoidList object. (6) find an Ellipsoid object in the Ellipsoid List object, (1) edit an Ellipsoid object in the Ellipsoid List object, and (8) quit the program Design: The main method should print a list of options with the action code and a short description followed by a line with just the action codes prompting the user to select an action. After the user enters an action code, the action is performed, including output if any. Then the ling with just the action codes prompting the user to select an action is printed again to accept the next code. The first action a user would normally perform is 'R' lo read in the file and create an Ellipsoid List object. However, the other action codes should work even if an input file has not been processed. The user may continue to perform actions until Q is entered to quit (or end) the program. Note that your program should accept both uppercase and lowercase action codes. Below is output produced afier printing the action codes with short descriptions, followed by the prompt with the action codes waiting for the user to select. Linc# Program output Ellipsoid List System Menu R - Read File and Create Ellipsoid List P - Print Ellipsoid List S - Print Summary Add Ellipsoid Delete Ellipsoid 7 F - Find Ellipsoid E - Edit Ellipsoid Q- Quit 10 Enter Code R, P, S, A, D, F, E, or 21: A D Below shows the screen aficr the user entered T and then (when prompted) the file namc. Notice the oulput from this action was "File read in and Ellipsoid List created". This is followed by the prompt with the action codes waiting for the user to make the next selection. You should use the Ellipsoid data l.txt file from Project 5 to test your program. Line Program output 1 Enter Code [R, P, S, A, D, T, E, or 2): r 2 File Name: Ellipsoid_data_1.txt File read in and Ellipsoid List created 4 5 Enter Code [R, P, S, A, D, T, E, or o]: Page 6 of 10 Project: Ellipoid List Menu App Page 7 of 10 The result of the user selecting 'p' to Print Ellipsoid List is shown below and next page. Line # Program output Enter Code [R, P, S, A, D, F, E, or 0]: P 2 Ellipsoid Test List Ellipsoid "Ex l" with axes a = 1.0, b = 2.0, c = 3.0 units has: volume = 25.1327 cubic unita 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, o = 345.6 units has: volume = 41,890,963.5508 cubic units surface area = 674, 164.7034 square units 15 16 Enter Code R, P, S, A, D, F, E, or : The result of the user selecting is to print the summary for the list is shown below. Line # Program Output Enter Code [R, P, S, A, D, F, E, or 0]: 9 2 3 ----- Summary for Ellipsoid Test List 4 Number of Ellipsoid objects: 3 5 Total Volume: 41,891,380.796 cubic units 6 Total Surface Area: 674,531.564 aquare units 7 Average Volurue: 13,963,793.599 cubic units 8 Average Surface Area: 224,843.855 square units 9 10 Enter Code R, P, S, A, D, F, E, or 21: Page 7 of 10 Project: Ellipoid List Menu App Page 8 of 10 The result of the user selecting a to add an Ellipsoid object is shown below. Note that after a was entered the user was prompted for label, radius, and height. Then after the Ellipsoid object is added to the Ellipsoid List, the message *** Ellipsoid added ***" was printed. This is followed by the prompt for the next action. After you do an add" you should do a print" or a "find" to confirm that the add" was successful. Line # Program output 1 1 Enter Code [R, P, S, A, D, F, E, or 21: a 2 label: EX 4 3 a: 10.2 4 b: 12.4 5 C: 14.6 6 *** Ellipsoid added *** 7 8 Enter Code [R, P, S, A, D, F, E, or 21: Here is an example of the successful "delete" for an Ellipsoid object, followed by an attempt that was not successful (i.e., the Ellipsoid object was not found). You should do "p to confirm the "d". Note that if found, the actual label "Ex 3" is printed below rather than "ex 3" which was entered by the user: whercas, if not found, the label entered by the user is printed, Line # Program output 1 Enter Code R, P, S, A, D, F, E, or ]: d 2 label: ex 3 3 "Ex 3" deleted 4 5 Enter Code [R, P, S, A, D, F, E, or 0]: d 6 label: Ox 17 7 "ex 17" not found 8 9 Enter Code R, P, S, A, D, F, B, or 21: Here is an example of the successful "find for an Ellipsoid object, followed by an attempt that was not successful (1.c., the Ellipsoid object was not found). Line Program output 1 Enter Code [R, P, S, A, D, F, E, or 0]: E 2 label: ex 2 3 Ellipsoid "Ex 2" with axes a = 2.3, b = 5.5, c = 7.4 units has: 4 volume = 392.1127 cubic units 5 surface area = 317.9245 square units 7 8 9 10 11 Enter Code [R, P, S, A, D, F, E, or 0]: f label: X 7 "ex 7" not found Enter Code [R, P, S, A, D, F, E, or 01: Page 8 of 10 Project: Ellipoid List Menu App Page 9 of 10 Here is an example of the successful "edit" for an Ellipsoid object, followed by an attempt that was not successful (i.e., the Ellipsoid object was not found). In order to verify the edit, you should do a "find" for "Ex 2" or you could do a "print" to print the whole list. Note that if found, the actual label "Ex 2" is printed below rather than "cx 2" which was entered by the user. whereas, if not found, the label entered by the liser is printed. Line # Program output 1 Enter Code [R, P, S, A, D, F, E, or 21: e 2 label: ex 2 a: 4.6 4 b: 11.0 5 C: 14.8 "Ex 2" successfully edited 7 8 Enter Code [R, P, S, A, D, F, E, or 21: e 9 label: ex 13 10 a: 12 11 b: 13 12 C: 14 C 13 "ex 13" not found 14 15 Enter Code (R, P, S, A, D, F, E, or 21: Finally, below is an example of entering an invalid code, followed by an example of entering a 'q' to quit the application which successfully terminates the program Line # Program output 1 1 Enter Code [R, P, S, A, D, F, E, or 0]: b 2 *** invalid code *** 3 4 Enter Code [R, P, S, A, D, F, E, or 01:9 5 Code and Test: Important considerations: This class should import java.util.Scanner, java.util.ArrayList, and java.io.FileNotFoundException. Carefully consider the following information as you develop this class 1. At the beginning of your main method, you should declare and create an ArrayList of Ellipsoid objects and then declare and create an Ellipsoid List object using the list name and the ArrayList as the parameters in the constructor. This will be an EllipsoidList object that contains no Ellipsoid objects. For example: String = "*** na list name assigned ***": ArrayLiat ellipsoid = new Array-catclipsoid>:11 Ellipsoidust = -en silipsoidlist: The 'R' option in the menu should invoke the readFile method on your EllipsoidList object. This will retum a new EllipsoidList object based on the data read from the file and this new 17 Page 9 of 10
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started