COMP1210 – Deliverables Solved

$ 24.99
Category:

Description

Files to submit to Web-CAT (all three files must be submitted together):
• Octahedron.java
• OctahedronList.java
• OctahedronListMenuApp.java

Specifications
Overview: You will write a program this week that is composed of three classes: the first class defines Octahedron objects, the second class defines OctahedronList objects, and the third, OctahedronListMenuApp, presents a menu to the user with eight options and implements these: (1) read input file (which creates an OctahedronList object), (2) print report, (3) print summary, (4) add an Octahedron object to the OctahedronList object, (5) delete an Octahedron object from the OctahedronList object, (6) find an Octahedron object in the OctahedronList object, (7) Edit an
Octahedron in the OctahedronList object, and (8) quit the program. [You should create a new
“Project 6” folder and copy your Project 5 files (Octahedron.java, OctahedronList.java,
Octahedron_data_1.txt, and Octahedron_data_0.txt) to it, rather than work in the same folder as Project 5 files.]

An Octahedron is a is a polyhedron with eight faces, twelve edges, and six vertices. The term is most commonly used to refer to the regular octahedron, a Platonic solid composed of eight equilateral triangles, four of which meet at each vertex. The formulas are provided to assist you in computing return values for the respective methods in the Octahedron class described in this project. Source: Wikipedia and Merriam-Webster.

Formulas for surface area (A) and volume (V) are shown below where 𝑎 is the length of an edge.

𝐴 (

𝑉

• Octahedron.java (assuming that you successfully created this class in the previous project, just copy the file to your new project folder and go on to OctahedronList.java on page 4. Otherwise, you will need to create Octahedron.java as part of this project.)

Requirements: Create an Octahedron class that stores the label, color, and edge length, which must be non-negative. The Octahedron 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 the Octahedron object, and a method to provide a String value of an Octahedron object (i.e., a class instance).
Design: The Octahedron 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 zero in their respective declarations. These instance variables should be private so that they are not directly accessible from outside of the Octahedron class, and these should be the only instance variables in the class.

(2) Constructor: Your Octahedron class must contain a public constructor that accepts three 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 Octahedron 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.

Octahedron ex1 = new Octahedron (“Ex 1”, “orange”, 5.2);
Octahedron ex2 = new Octahedron (” Ex 2 “, “blue”, 20.4);
Octahedron ex3 = new Octahedron (“Ex 3”, “orange and blue”, 104.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 Octahedron, 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 label field is set to the “trimmed” String and the method returns true. Otherwise, the method returns false and the label field is not set.
o getColor: Accepts no parameters and returns a String representing the color field.
o 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 true. Otherwise, the method returns false and the label is not set.
o getEdge: Accepts no parameters and returns a double representing the edge field.
o setEdge: Accepts a double parameter and returns a boolean as follows. If the edge is non-negative, sets the edge field to the double passed in and returns true. Otherwise, the method returns false and the edge is not set.
o surfaceArea: Accepts no parameters and returns the double value for the surface area calculated using the value for edge.
o volume: Accepts no parameters and returns the double value for the volume calculated using the value for edge.
o surfaceToVolumeRatio: Accepts no parameters and returns the double value calculated by dividing the surface area by the volume.
o toString: Returns a String containing the information about the Octahedron object formatted as shown below, including decimal formatting (“#,##0.0###”) for the double values. The newline ( ) and tab ( ) escape sequences should be used to achieve the proper layout for the indented lines (use rather than three spaces for the indentation). 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 ( ) character). The toString value for ex1, ex2, and ex3 respectively are shown below (the blank lines are not part of the toString values).

Octahedron “Ex 1” is “orange” with 12 edges of length 5.2 units.
surface area = 93.6693 square units volume = 66.2832 cubic units surface/volume ratio = 1.4132
Octahedron “Ex 2” is “blue” with 12 edges of length 20.4 units.
surface area = 1,441.6205 square units volume = 4,002.066 cubic units surface/volume ratio = 0.3602

Octahedron “Ex 3” is “orange and blue” with 12 edges of length 104.5 units.
surface area = 37,828.8557 square units volume = 537,950.8703 cubic units surface/volume ratio = 0.0703

• OctahedronList.java – extended from the previous project by adding the last six methods below. (Assuming that you successfully created this class in Project 5, just copy OctahedronList.java to your new Project 6 folder and then add the indicated methods. Otherwise, you will need to create all of OctahedronList.java as part of this project.)

Requirements: Create an OctahedronList class that stores the name of the list and an ArrayList of Octahedron objects. It also includes methods that return the name of the list, number of Octahedron objects in the OctahedronList, total volume, total surface area, average volume, average surface, and average surface to volume ratio for all Octahedron objects in the
OctahedronList. The toString method returns a String containing the name of the list followed by each Octahedron in the ArrayList, and a summaryInfo method returns summary information about the list (see below).

Design: The OctahedronList class has two fields, a constructor, and methods as outlined below.

(1) Fields (or instance variables): (1) a String representing the name of the list and (2) an ArrayList of Octahedron objects. These are the only fields (or instance variables) that this class should have, and both should be private.
(2) Constructor: Your OctahedronList class must contain a constructor that accepts a parameter of type String representing the name of the list and a parameter of type
ArrayList<Octahedron> representing the list of Octahedron objects. These parameters should be used to assign the fields described above (i.e., the instance variables).
(3) Methods: The methods for OctahedronList are described below.
o getName: Returns a String representing the name of the list.
o numberOfOctahedrons: Returns an int representing the number of Octahedron objects in the OctahedronList. If there are zero Octahedron objects in the list, zero should be returned.
o totalSurfaceArea: Returns a double representing the total surface area for all Octahedron objects in the list. If there are zero Octahedron objects in the list, zero should be returned.
o totalVolume: Returns a double representing the total volume for all Octahedron objects in the list. If there are zero Octahedron objects in the list, zero should be returned.
o averageSurfaceArea: Returns a double representing the average surface area for all Octahedron objects in the list. If there are zero Octahedron objects in the list, zero should be returned.
o averageVolume: Returns a double representing the average volume for all
Octahedron objects in the list. If there are zero Octahedron objects in the list, zero should be returned.
o averageSurfaceToVolumeRatio: Returns a double representing the average of the surface to volume ratios for all Octahedron objects in the list (i.e., the sum of the surface to volume ratios for all Octahedron in the list divided by the number of Octahedron objects). If there are zero Octahedron objects in the list, zero should be returned.
o toString: Returns a String (does not begin with ) containing the name of the list followed by each Octahedron in the ArrayList. In the process of creating the return result, this toString() method should include a while loop that calls the toString() method for each Octahedron object in the list (adding a before and after each). Be sure to include appropriate newline escape sequences. For an example, see lines 3 through 19 in the output below from OctahedronListApp for the Octahedron_data_1.txt input file. [Note that the toString result should not include the summary items in lines 21 through 27 of the example. These lines represent the return value of the summaryInfo method below.]
o summaryInfo: Returns a String (does not begin with ) containing the name of the list (which can change depending of the value read from the file) followed by various summary items: number of Octahedron objects, 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 21 through 27 in the output below from OctahedronListApp for the Octahedron_data_1.txt input file. The second example below shows the output from OctahedronListApp for the
Octahedron_data_0.txt input file which contains a list name but no Octahedron data.

• The following six methods are new in Project 6:
o getList: Returns the ArrayList of Octahedron objects (the second field above).
o readFile: Takes a String parameter representing the file name, reads in the file, storing the list name and creating an ArrayList of Octahedron objects, uses the list name and the ArrayList to create an OctahedronList object, and then returns the OctahedronList object. See note #1 under Important Considerations for the OctahedronListMenuApp class (last page) to see how this method should be called.
o addOctahedron: Returns nothing but takes three parameters (label, color, and edge), creates a new Octahedron object, and adds it to the OctahedronList object (i.e., adds it to the ArrayList of Octahedron objects in the OctahedronList object).
o findOctahedron: Takes a label of an Octahedron as the String parameter and returns the corresponding Octahedron object if found in the OctahedronList object; otherwise returns null. Case should be ignored when attempting to match the label.
o deleteOctahedron: Takes a String as a parameter that represents the label of the Octahedron and returns the Octahedron if it is found in the OctahedronList object and deleted; otherwise returns null. Case should be ignored when attempting to match the label; consider calling/using findOctahedron in this method.
o editOctahedron: Takes three parameters (label, color, and edge), uses the label to find the corresponding the Octahedron object. If found, sets the color and edge to the values passed in as parameters, and returns the Octahedron object. If not found, returns null. This method should not change the label.

• OctahedronListMenuApp.java (replaces OctahedronListApp class from the previous project)

Requirements: Create an OctahedronListMenuApp class with a main method that presents the user with a menu with eight options, each of which is implemented to do the following: (1) read the input file and create an OctahedronList object, (2) print the OctahedronList object, (3) print the summary for the OctahedronList object, (4) add an Octahedron object to the OctahedronList object, (5) delete an Octahedron object from the OctahedronList object, (6) find an Octahedron object in the OctahedronList object, (7) edit an Octahedron object in the OctahedronList object, and (8) quit the program.

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 select.

Line # Program output

1
2
3
4
5
6
7
8
9
10 —-jGRASP exec: java OctahedronListMenuApp
Octahedron List System Menu
R – Read File and Create Octahedron List
P – Print Octahedron List
S – Print Summary
A – Add Octahedron
D – Delete Octahedron
F – Find Octahedron
E – Edit Octahedron
Q – Quit
Enter Code [R, P, S, A, D, F, E, or Q]:

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 Octahedron 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 Octahedron_data_1.txt file from Project 5 to test your program.

Line # Program output
1
2
3
4
5 Enter Code [R, P, S, A, D, F, E, or Q]: r
File Name: Octahedron_data_1.txt
File read in and Octahedron List created

Enter Code [R, P, S, A, D, F, E, or Q]:

The result of the user selecting ‘p’ to Print Octahedron List is shown below and next page.

Line # Program output
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Enter Code [R, P, S, A, D, F, E, or Q]: p
Octahedron Test List

Octahedron “Ex 1” is “orange” with 12 edges of length 5.2 units.
surface area = 93.6693 square units volume = 66.2832 cubic units surface/volume ratio = 1.4132

Octahedron “Ex 2” is “blue” with 12 edges of length 20.4 units. surface area = 1,441.6205 square units volume = 4,002.066 cubic units surface/volume ratio = 0.3602

Octahedron “Ex 3” is “orange and blue” with 12 edges of length 104.5 units.
surface area = 37,828.8557 square units volume = 537,950.8703 cubic units surface/volume ratio = 0.0703

Enter Code [R, P, S, A, D, F, E, or Q]:

The result of the user selecting ‘s’ to print the summary for the list is shown below.

Line # Program output
1
2
3
4
5
6
7
8
9
10
11
Enter Code [R, P, S, A, D, F, E, or Q]: s
—– Summary for Octahedron Test List —–
Number of Octahedrons: 3
Total Surface Area: 39,364.145
Total Volume: 542,019.22
Average Surface Area: 13,121.382 Average Volume: 180,673.073
Average Surface/Volume Ratio: 0.615

Enter Code [R, P, S, A, D, F, E, or Q]:

The result of the user selecting ‘a’ to add an Octahedron object is shown below. Note that after ‘a’ was entered, the user was prompted for label, color, and edge. Then after the Octahedron object is added to the Octahedron List, the message “*** Octahedron 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
2
3
4
5
6
7 Enter Code [R, P, S, A, D, F, E, or Q]: a
Label: Ex 4
Color: gold
Edge: 10.5
*** Octahedron added ***

Enter Code [R, P, S, A, D, F, E, or Q]:

Here is an example of the successful “delete” for an Octahedron object, followed by an attempt that was not successful (i.e., the Octahedron object was not found). You should do “p” to confirm the “d”. Note that if found, the actual label “Ex 2” is printed below rather than “ex 2” which was entered by the user; whereas, if not found, the label entered by the user is printed.

Line # Program output
1
2
3
4
5
6
7
8
9
Enter Code [R, P, S, A, D, F, E, or Q]: d
Label: ex 2
“Ex 2” deleted

Enter Code [R, P, S, A, D, F, E, or Q]: d
Label: ex 99
“ex 99” not found

Enter Code [R, P, S, A, D, F, E, or Q]:

Here is an example of the successful “find” for an Octahedron object, followed by an attempt that was not successful (i.e., the Octahedron object was not found).

Line # Program output
1
2
3
4
5
6
7
8
9
10
11
13
Enter Code [R, P, S, A, D, F, E, or Q]: f
Label: ex 3
Octahedron “Ex 3” is “orange and blue” with 12 edges of length 104.5 units. surface area = 37,828.8557 square units volume = 537,950.8703 cubic units surface/volume ratio = 0.0703

Enter Code [R, P, S, A, D, F, E, or Q]: f
Label: ex 88
“ex 88” not found

Enter Code [R, P, S, A, D, F, E, or Q]:

Here is an example of the successful “edit” for an Octahedron object, followed by an attempt that was not successful (i.e., the Octahedron object was not found). In order to verify the edit, you should do a “find” for “Ex 3” or you could do a “print” to print the whole list. Note that if found, the actual label “Ex 3” is printed below rather than “ex 3” which was entered by the user; whereas, if not found, the label entered by the user is printed.

Line # Program output
1
2
3
4
5
6
7
8
9
10
11
12
13 Enter Code [R, P, S, A, D, F, E, or Q]: e
Label: ex 3
Color: silver
Edge: 10.5
“Ex 3” successfully edited

Enter Code [R, P, S, A, D, F, E, or Q]: e
Label: ex 77
Color: green
Edge: 12.7
“ex 77” not found

Enter Code [R, P, S, A, D, F, E, or Q]:

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
2
3
4
5 Enter Code [R, P, S, A, D, F, E, or Q]: C
*** invalid code ***

Enter Code [R, P, S, A, D, F, E, or Q]: q

—-jGRASP: operation complete.

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 a String for the list name and assign it as shown below and also declare and create an ArrayList of Octahedron objects. Then declare and create an OctahedronList object using the list name and the ArrayList as the parameters in the constructor. This will be an OctahedronList object that contains no Octahedron objects. For example:
ArrayList<Octahedron> _________ = new ArrayList<Octahedron>();
OctahedronList _________ = new OctahedronList(_________,_________);

The ‘R’ option in the menu should invoke the readFile method on your OctahedronList

Page

2. Very Important: You should declare only one Scanner on System.in for your entire program, and this should be done in the main method. That is, all input from the keyboard (System.in) must be done in your main method. Declaring more than one Scanner on System.in in your program will likely result in a very low score from Web-CAT.

3. For the menu, your switch statement expression should evaluate to a char, and each case should be a char; alternatively, your switch statement expression should evaluate to a String with a length of 1, and each case should be a String with a length of 1.

Page

Reviews

There are no reviews yet.

Be the first to review “COMP1210 – Deliverables Solved”

Your email address will not be published. Required fields are marked *