Question
JAVA HELP: I have the first two files. Just need help figuring out the DodecahedronListMenuApp file (pages 6-10) The code I already have for the
JAVA HELP: I have the first two files. Just need help figuring out the DodecahedronListMenuApp file (pages 6-10) The code I already have for the first two files copy and pasted below the assignment. Thank you!
import java.text.DecimalFormat;
public class Dodecahedron { private String label; private String color; private double edge; // parametrized constructor public Dodecahedron(String lbl, String clr, double edg) { label= lbl; color = clr; edge = edg; }
public String getLabel() { return label; }
public void setLabel(String label) { this.label = label; }
public String getColor() { return color; }
public void setColor(String color) { this.color = color; }
public double getEdge() { return edge; }
public void setEdge(double edge) { this.edge = edge; } public double surfaceArea() { return 3*Math.sqrt(25 + 10*Math.sqrt(5)) * edge* edge; } public double volume() { return ((15 + 7 * Math.sqrt(5)) / 4) * Math.pow(edge, 3); } public double surfaceToVolumeRatio() { return surfaceArea() / volume(); } @Override public String toString() { DecimalFormat fmt = new DecimalFormat("#,##0.0##"); return "Dodecahedron \"" + label + "\" is \"" + color + "\" with 30 " + " edges of length " + edge + "units. " + "surface area = " + fmt.format(surfaceArea()) + " square units" + " " + "volume = " + fmt.format(volume()) + " cubic units" + " " + "surface/volume ratio = " + fmt.format(surfaceToVolumeRatio()); }
}
import java.io.File; import java.io.IOException; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Scanner;
public class DodecahedronList { // instance variables private String listName; private ArrayList dlist; public DodecahedronList(String name, ArrayList dObjects) { listName = name; dlist = dObjects; } public String getName() { return listName; } public int numberOfDodecahedrons() { return dlist.size(); } public double totalSurfaceArea() { double total = 0; for(Dodecahedron decahedron:dlist) { total += decahedron.surfaceArea(); } return total; } public double totalVolume() { double total = 0; for(Dodecahedron decahedron:dlist) { total += decahedron.volume(); } return total; } public double averageSurfaceArea() { int numDecah = numberOfDodecahedrons(); if(numDecah == 0) return 0; return totalSurfaceArea() / numDecah; } public double averageVolume() { int numDecah = numberOfDodecahedrons(); if(numDecah == 0) return 0; return totalVolume() / numDecah; } public double averageSurfaceToVolumeRatio() { return averageSurfaceArea() / averageVolume(); } @Override public String toString() { String msg = "List: " + listName + " "; int i = 0; while(i
}
Project: Dodecahedron List Menu App Page 1 of 10 Deliverables Your project files should be submitted to Web-CAT by the due date and time specified. You may submit your files to the skeleton code assignment until the project due date but should try to do this prior to the due date (there is no late penalty for the skeleton code assignment since it is ungraded for this project). The files you submit to skeleton code assignment may be incomplete in the sense that method bodies have at least a return statement if applicable or they may be essentially completed files. In order to avoid a late penalty for the projcct, you must submit your complcted code files to Web-CAT no later than 11:59 PM on the due date for the completed code. If you are unable to submit via Web-CAT, you should e-mail your project Java files in a zip file to your TA before the deadline Files to submit to Web-CAT (all three files must be submitted together) Dodecahedron.java DodecahedronList.java .DodecahedronListMenuApp.java Specifications Overview: You will write a program this week that is composed of three classes: the first class defines Dodecahedron objects, the second class defines DodecahedronList objects, and the third, DodecahedronListMenuApp, presents a menu to the user with eight options and implements these: (1) read input file (which creates a DodecahedronList object), (2) print report, (3) print summary, (4) add a Dodecahedron object to the DodecahedronList object, (5) delete a Dodecahedron object from the DodecahedronList object, (6) find a Dodecahedron object in the DodecahedronList object, (7) Edit a Dodecahedron in the DodecahedronList object, and (8) quit the program. [You should create a new Project 6" folder and copy your Project 5 files (Dodecahedronjava. DodecanearonListJava, dodecahedron data 1.txt, and dodecahedron_data 0.txt) to it, rather than work in the same folder as Project 5 files.] A dodecahedron has 12 equal pentagonal faces, 20 vertices, and 30 edges as depicted below. The formulas are provided to assist you in computing return values for the respective Dodecahedron methods described in this project Surface Area (A) Volume (V) Edge length (a) Surface/Volume ratio (A/V) A 3 25+10 5 a 15+7 /5 4 Page 1 of 10 Project: Dodecahedron List Menu App Page 2 of 10 Dodecahedron.java (assuming that you successfully created this class in Project 4, just copy the file to your new Project 6 folder and go on to DodecahedronList.java on page 4 Otherwise, you will need to create Dodecahedron.java as part of this project.) Requirements: Create a Dodecahedron class that stores the label, color, and edge (i.e., length of an edge, which must be greater than zero). The Dodecahedron class also includes methods to set and get each of these fields, as well as methods to calculate the surface area, volume, and surface to volume ratio of a Dodecahedron object, and a method to provide a String value of a Dodecahedron object (i.e., a class instance) Design: The Dodecahedron class has fields, a constructor, and methods as outlined below (1) Fields (instance variables): label of type String, color of type String, and edge of type double Initialize the Strings to ""and the double to 0 in their respective declarations. These instance variables should be private so that they are not directly accessible from outside of the Dodecahedron class, and these should be the only instance variables in the class (2) Constructor: Your Dodecahedron class must contain a public constructor that accepts threc parameters (see types of above) representing the label, color, and edge. Instead of assigning the parameters directly to the fields, the respective set method for each field (described below) should be called. For example, instead of the statement label-labelIn; use the statement setLabel (labelIn); Below are examples of how the constructor could be used to create Dodecahedron objects. Note that although String and numeric literals are used for the actual parameters (or arguments) in these examples, variables of the required type could have been used instead of the literals Dodecahedron examplel-new Dodecahedron ( "Small Example", "blue", 0.25) Dodecahedron example2 = new Dodecahedron (" Medium Example ", "orange", 10.1); Dodecahedron example3 = new Dodecahedron ("Large Example", "silver ", 200.5); (3) Methods: Usually a class provides methods to access and modify each of its instance variables (known as get and set methods) along with any other required methods. The methods for Dodecahedron, which should each be public, are described below. See formulas in Code and Test below o getLabel: Accepts no parameters and returns a String representing the label field. o setLabel: Takes a String parameter and returns a boolean. If the string parameter is not null, then the "trimmed" String is set to the label field and the method returns true Otherwise, the method returns false and the label is not set. o getColor: Accepts no parameters and returns a String representing the color field. setColor: Takes a String parameter and returns a boolean. If the string parameter is not null, then the "trimmed" String is set to the color field and the method returns truc Otherwise, the method returns false and the labe is not set. o Page 2 of 10 Project: Dodecahedron List Menu App Page 3 of 10 o getEdge: Accepts no parameters and returns a double representing the edge field setEdge: Accepts a double parameter and returns a boolean as follows. If the edge is greater than zero, sets the edge field to the double passed in and returns truc. Otherwise, the method returns false and the edge is not set. o o surfaceArea: Accepts no parameters and returns the double value for the total o volume: Accepts no parameters and returns the double value for the volume calculated o surfaceToVolumeRatio: Accepts no parameters and returns the double valuc o toString: Returns a String (does not begin with n) containing the information about surface area calculated using the value for edge using the value for edge calculated by dividing the total surface area by the volume the Dodccahedron object formatted as shown below, including decimal formatting ("#,##0.0##") for the double values. Newline and tab escape sequences should be used to achieve the proper layout. In addition to the field values (or corresponding "get methods), the following methods should be used to compute appropriate values in the toString method: surfaceArea), volume), and surfaceToVolumeRatio. Each line should have no trailing spaces (e.g., there should be no spaces before a newline ^n) character). The toString value for examplel, example2, and example3 respectively are shown below (the blank lines are not part of the toString values) Dodecahedron "Small Example" is "blue" with 30 edges of length 0.25 units. surface area 1.29 square units volume 0.12 cubic units surface/volume ratio 10.777 Dodecahedron "Medium Example" is "orange" with 30 edges of length 10.1 units surface area-2,106.071 squar units volume = 7,895.319 cubic units surface/volume ratio-0.267 Dodecahedron "Large Example" is "silver" with 30 edges of length 200.5 units surface area = 829,963.459 square units volume = 61,765,889.248 cubic units surface/volume ratio-0.013 Code and Test: As you implement your Dodecahedron class, you should compile it and then test it using interactions. For example, as soon you have implemented and successfully compiled the constructor, you should create instances of Dodecahedron in interactions (e.g., copy/paste the cxamples above). Remember that when you have an instance on the workbench, you can unfold it to sec its values. You can also open a viewer canvas window and drag the instancc from the Workbench tab to the canvas window. After you have implemented and compiled one or more methods, create a Dodecahedron object in interactions and invoke each of your methods on the object to make sure the methods are working as intended. You may find it useful to create a separate class with a main method that creates an instance of Dodecahedron then prints it out Page 3 of 10 Project: Dodecahedron List Menu App Page 4 of 10 DodecahedronList.java - extended from Project 5 by adding the last six methods below Assuming that you successfully created this class in Project 5. just co DodecahedronList.java to your new Project 6 folder and then add the indicated methods Otherwisc, you will necd to create all of DodccahedronList.java as part of this projcct.) Requirements: Create a DodecahedronList class that stores the name of the list and an ArrayList of Dodecahedron objects. It also includes methods that return the name of the list, number of Dodecahedron objects in the DodecahedronList, total surface area, total volume, average surface area, average volume, and average surface to volume ratio for all Dodecahedron objects in the DodecahedronList. The toString method returns a String containing the name of the list followed by each Dodecahedron in the ArrayList, and a summaryInfo method returns summary information about the list (see below) Design: The DodecahedronList class has two fields, a constructor, and methods as outlined ow (1) Fields (or instance variables): (1) a String representing the name of the list and (2) an ArrayList of Dodecahedron objects. These are the only fields (or instance variables) that this class should have (2) Constructor: Your DodecahedronList class must contain a constructor that accepts a parameter of type String representing the name of the list and a parameter of type ArrayList representing the list of Dodecahedron objects. These parameters should be used to assign the fields described above (i.e., the instance variables) (3) Methods: The methods for DodecahedronList are described below getName: Returns a String representing the name of the list. numberOfDodecahedrons: Returns an int representing the number of Dodecahedron objects in the DodecahedronList. If there are zero Dodecahedron objects in the list, zero should be returned. totalSurfaceArea: Returns a double representing the total surface areas for all Dodecahedron objects in the list. If there are zero Dodecahedron objects in the list, zero should be returned o o o o totalVolume: Returns a double representing the total volumes for al Dodecahedron objects in the list. If there are zero Dodecahedron objects in the list, zero should be returned. o averageSurfaceArea: Returns a double representing the average surface area for l Dodecahedron objects in the list. If there are zero Dodccahedron objects in the list, zero should be returned. averageVolume: Returns a double representing the average volume for all Dodecahedron objects in the list. If there are zero Dodecahedron objects in the list, zero should be returned. o averageSurfaceToVolumeRatio: Returns a double representing the average surface to volume ratio for all Dodecahedron objects in the list. If there are zero Dodccahedron objects in the list, zero should be returned. o Page 4 of 10 Project: Dodecahedron List Menu App Page 5 of 10 tostring: Returns a String (does not begin with In) containing the name of the list followed by each Dodecahedron in the ArrayList. In the process of creating the return result, this toString) method should include a while loop that calls the toString) methood for each Dodecahedron object in the list (adding a before and after each). Be sure to include appropriate newline escape sequences. For an example, see lines 2 through 19 in the output below from DodecahedronListApp for the Dodecahedron data 1.txt input file. Note that the toString result should not include the summary items in lines 20 through 26 of the example. These lines represent the return value of the summaryInfo method below o o summaryInfo: Returns a String (does not begin with 'n) containing the name of the list (which can change depending of the value read from the file) followcd by various summary items: number of Dodecahedrons, total surface area, total volume, average surface area, average volume, and average surface to volume ratio. Use "#,##0.0##" as the pattern to format the double values. For an example, see lines 20 through 26 in the output below from DodecahedronListApp for the Dodecahedron data l.txt input file The sccond example below shows the output from DodecahedronListApp for the Dodecahedron data 0.xt input file which contains a list name but no other data The following six methods are new in Project 6: o getList: Returns the ArrayList of Dodecahedron objects (the second field above) readFile: Takes a String parameter representing the file name, reads in the file storing thc list namc and creating an ArrayList of Dodccahcdron objects, uses the list name and the ArrayList to create a DodecahedronList object, and then returns the Dodec ahedronList object. See note #1 under Important Considerations for the DodecahedronListMenuApp class (last page) to see how this method should be called addDodecahedron: Returns nothing but takes three parameters (label, color, and edge), creates a new Dodecahedron object, and adds it to the DodecahedronList object. findDodecahedron: Takes a label of a Dodecahedron as the String parameter and returns the corresponding Dodecahedron object if found in the DodecahedronList object; otherwise returns null. Case should be ignored when attempting to match the label deleteDodecahedron: Takes a String as a parameter that represents the label of the Dodecahedron and returns the Dodecahedron if it is found in the DodecahedronList object and deleted; otherwise returns null. Case should be ignored when attempting to match the label; consider calling/using findDodecahedron in this method o o o o editDodecahedron: Takes three parameters (label, color, and edge), uses the label to find the corresponding the Dodecahedron object. If found, sets the color and edge to the values passed in as parameters, and returns true. If not found, returns false o Code and Test: Remember to import java.util.ArrayList, java.util.Scanner, java.io.File java.io.IOException. These classes will be necded in the readFile mcthod which will require a throws clause for IOException. Some of the methods above require that you use a loop to go through the objects in the ArrayList. You may want to implement the class below in parallel with this one to facilitate testing. That is, after implementing one to the methods above, you can implement the corresponding "case" in the switch for menu described below in thoe DodecahedronListMenuApp class Page 5 of 10 Project: Dodecahedron List Menu App Page 6 of 10 DodecahedronListMenuApp.java (replaces DodecahedronListApp class from Project 5) Requirements: Create a DodecahedronListMenuApp class with a main method that presents the user with a menu with eight options, each of which is implemented to do the following: () read the input file and create a DodecahedronList object, (2) print the DodecahedronList object, (3) print the summary for the DodecahedronList object, (4) add a Dodecahedron object to the DodecahedronList object, (5) delete a Dodecahedron object from the DodecahedronList object, (6) find a Dodecahedron object in the DodecahedronList object, (7) Edit a Dodecahedron object in the DodecahedronList 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 line 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' to read in the file and create a DodecahedronList 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 after printing the action codes with short descriptions followed by the prompt with the action codes waiting for the user to make a selection. Line # | Program output Dodecahedron List System Menu RRead File and Create Dodecahedron List P Print Dodecahedron List s - Print Summary A- Add Dodecahedron DDelete Dodecahedron F-Find Dodecahedron E-Edit Dodecahedron Q- Quit Enter Code [R, P, S, A, D, F, E, or Q1 Below shows the screen after the user entered r and then (when prompted) the file name. Notice the output from this action was "File read in and Dodecahedron 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 dodecahedron data 1.txt file from Project 5 to test your program Line # | Program output Enter Code [R, P, S, A, D, F, E, or Q1: r File name: dodecahedron data 1.txt File read in and Dodecahedron List created Enter Code [R, P, S, A, D, F, E, or Q]: Page 6 of 10 Project: Dodecahedron List Menu App Page 7 of 10 The result of the user selecting 'p' to Print Dodecahedron List is shown below and next page Line # | Program output Enter Code [R, P, S, A, D, F, E, or Q1: P Dodecahedron Test List Dodecahedron "Small Example" is "blue" with 30 edges of length 0.25 units. surface area = 1.29 square units volume = 0.12 cubic units surface/volume ratio - 10.777 Dodecahedron "Medium Example" is orange" with 30 edges of length 10.1 units. surface area 2,106.071 square units volume = 7,895.319 cubic units surface/volume ratio-0.267 12 13 Dodecahedron "Large Example" is "silver" with 30 edges of length 200.5 units. 15 16 17 18 19 surface area- 829,963.459 square units volume 61,765,889.248 cubic units surface/volume ratio-0.013 Enter Code [R, P, S, A, D, F, E, or Q1: The result of the user selecting 's' to print the summary for the list is shown below Line # | Program output Enter Code [R, P, S, A, D, F, E, or Q]: s -- Summary for Dodecahedron Test List - Number of Dodecahedrons: 3 Total Surface Area: 832,070.821 Total Volume: 61,773,784.687 Average Surface Area: 277,356.94 Average Volume: 20,591,261.562 Average Surface/Volume Ratio: 3.686 10 Enter Code [R, P, S, A, D, F, E, or 01: The result of the user selecting 'a' to add a Dodecahedron object is shown below. Note that after a' was entered, the user was prompted for label, color, and edge. Then after the Dodecahedron object is added to the Dodecahedron List, the message Dodecahedron 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 # | Pro output Enter Code [R, P, S, A, D, F, E, or 01: a Label: dl Color: gold Edge: 5.8 Dodecahedron added Enter Code R, P. S, A, D, F, E, or Q1: Page 7 of 10 Project: Dodecahedron List Menu App Page 8 of 10 Here is an example of the successful "delete" for a Dodecahedron object, followed by an attempt that was not successful (i.e., the Dodecahedron object was not found). Do "p to confirm the d" Line # | Program output Enter Code [R, P, S, A, D, F, E, or Q1: d Label: Medium Example "Medium Example" deleted Enter Code [R, P, S, A, D, F, E, or ol: od Label: not a real object "not a real object" not found Enter Code [R, P, S, A, D, F, E, or Q1: Here is an example of the successful "find" for a Dodecahedron object, followed by an attempt that was not successful (i.c., the Dodecahedron object was not found). Line # | Program output Enter code [R, P, S, A, D, F, E, or Q]f Label: small EXAMPLE Dodecahedron "Small Example" is "blue" with 30 edges of length 0.25 units surface area 1.29 square units volume = 0.12 cubic units surface/volume ratio = 10.777 Enter Code [R, P, S, A, D, F, E, or Q]: f Label: tiny obj "tiny obj" not found 12 Enter Code [R, P, S, A, D, F,E, or o1: Here is an example of the successful "edit" for a Dodecahedron object, followed by an attempt that was not successful (i.e., the Dodecahedron object was not found. In order to verify the edit, you should do a "find" for "wide example" or you could do a "print" to print the whole list. Line # | Program outp Enter Code [R, P, S, A, D, F. E, or Q: e Label: smal1 EXAMPLE Color: green Edge: 0.1 "small EXAMPLE" successfully edited Enter Code [R, P, S, A, D, F, E, or Q]: e Label: not there Color: yellow Edge: 12.4 "not there not found 12 13 Enter Code [R, P, S, A, D, F, E, or Q]: Page 8 of 10 Project: Dodecahedron List Menu App Page 9 of 10 Finally, below is an example of entering an invalid code, followed by an example of entering a q' to quit the application with no message Line # | Program output Enter code [R, P, S, A, D, F, E, or Q1: b invalid code Enter Code R, P, S, A, D, F. E, or Q1: q jGRASP: operation complete Code and Test Important considerations: This class should import java.util.Scanner, java.util.ArrayList, and java.io.IOException. 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 Dodecahedron objects and then declare and create a DodecahedronList object using the list name and the ArrayList as the parameters in the constructor. This will be a DodecahedronList object that contains no Dodecahedron objects. For example Scring Arrayist Dodecahedron> DodecahedronList -new ArrayListStep 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