Starting from:

$29.99

COMP1210 Deliverables Solution


Files to submit to Web-CAT:
Part A
• PentagonalPyramid.java, PentagonalPyramidTest.java
Part B
• PentagonalPyramid.java, PentagonalPyramidTest.java
• PentagonalPyramidList2.java, PentagonalPyramidList2Test.java

Specifications – Use arrays in this project; ArrayLists are not allowed!
Overview: This project consists of four classes: (1) PentagonalPyramid is a class representing an PentagonalPyramid object; (2) PentagonalPyramidTest class is a JUnit test class which contains one or more test methods for each method in the PentagonalPyramid class; (3) PentagonalPyramidList2 is a class representing an PentagonalPyramid list object; and (4) PentagonalPyramidList2Test class is a
JUnit test class which contains one or more test methods for each method in the
PentagonalPyramidList2 class. Note that there is no requirement for a class with a main method in this project.

Since you will be modifying classes from the previous project, I strongly recommend that you create a new folder for this project with a copy of your PentagonalPyramid class and PentagonalPyramidList2 class from the previous project.

You should create a jGRASP project and add your PentagonalPyramid class and
PentagonalPyramidList2 class. With this project is open, your test files will be automatically added to the project when they are created. You will be able to run all test files by clicking the JUnit run button on the Open Projects toolbar.

New requirements and design specifications are underlined in the descriptions below to help you identify them.

• PentagonalPyramid.java (a modification of the PentagonalPyramid class in the previous project; new requirements are underlined below)

Requirements: Create a PentagonalPyramid class that stores the label, base edge (i.e., length of an edge in the pentagonal base), and height. The base edge and height must be greater than zero. The PentagonalPyramid class also includes methods to set and get each of these fields, as well as methods to calculate the surface area and volume of a PentagonalPyramid object, and a method to provide a String value of a PentagonalPyramid object (i.e., a class instance).


A PentagonalPyramid has a pentagon base and five isosceles triangle faces, six vertices, and 10 edges as depicted below with base edge length a and height h. The formulas are provided to assist you in computing return values for the respective methods in the PentagonalPyramid class described in this project.
Ref: Do a “Google” search on “pentagonal pyramid surface area” for details and an interactive solver.



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

(1) Fields (instance variables): label of type String, base edge of type double, and height of type double. Initialize the String 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 PentagonalPyramid class, and these should be the only instance variables in the class. Class Variable - count of type int should be private and static, and it should be initialized to zero.

(2) Constructor: Your PentagonalPyramid class must contain a public constructor that accepts three parameters (see types of above) representing the label, base edge, height. 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 PentagonalPyramid 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.
The constructor should increment the class variable count each time an PentagonalPyramid is constructed.

PentagonalPyramid ex1 = new PentagonalPyramid("Ex 1", 1, 2);

PentagonalPyramid ex2 = new PentagonalPyramid(" Ex 2 ", 12.3, 25.5);
PentagonalPyramid ex3 = new PentagonalPyramid("Ex 3", 123.4, 900);

(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 PentagonalPyramid, 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 getBaseEdge: Accepts no parameters and returns a double representing the base edge field.
o setBaseEdge: Accepts a double parameter and returns a boolean as follows. If the double is greater than zero, sets the base edge field to the double passed in and returns true. Otherwise, the method returns false and does not set the base edge field.
o getHeight: Accepts no parameters and returns a double representing the height field.
o setHeight: Accepts a double parameter and returns a boolean as follows. If the double is greater than zero, sets the height field to the double passed in and returns true. Otherwise, the method returns false and does not set the height field.
o surfaceArea: Accepts no parameters and returns the double value for the total surface area calculated using formula above and the values of the base edge and height fields. See code and test below regarding the Math.tan(x) method. o volume: Accepts no parameters and returns the double value for the volume calculated using formula above and the values of the base edge and height fields.
o toString: Returns a String containing the information about the PentagonalPyramid 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() and volume(). 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).
PentagonalPyramid "Ex 1" with base edge = 1.0 and height = 2.0 units has:
surface area = 7.008203 square units volume = 1.1469849 cubic units

PentagonalPyramid "Ex 2" with base edge = 12.3 and height = 25.5 units has:
surface area = 1,086.4892066 square units volume = 2,212.4737204 cubic units PentagonalPyramid "Ex 3" with base edge = 123.4 and height = 900.0 units has: surface area = 305,081.9691528 square units volume = 7,859,601.8538338 cubic units


New method for this project
o getCount: A static method that accepts no parameters and returns an int representing the static count field. o resetCount: A static method that returns nothing, accepts no parameters, and sets the static count field to zero.
o equals: An instance method that accepts a parameter of type Object and returns false if the Object is a not an PentagonalPyramid; otherwise, when cast to an PentagonalPyramid, if it has the same field values as the PentagonalPyramid upon which the method was called. Otherwise, it returns false. Note that this equals method with parameter type Object will be called by the JUnit Assert.assertEquals method when two PentagonalPyramid objects are checked for equality.

Below is a version you are free to use.
public boolean equals(Object obj) {

if (!(obj instanceof PentagonalPyramid)) { return false;
} else {
PentagonalPyramid d = (PentagonalPyramid) obj; return (label.equalsIgnoreCase(d.getLabel()) && Math.abs(baseEdge - d.getBaseEdge()) < .000001)
&& Math.abs(height - d.getHeight()) < .000001);
}
}
o hashCode(): Accepts no parameters and returns zero of type int. This method is required by Checkstyle if the equals method above is implemented.

Code and Test: As you implement the methods in your PentagonalPyramid class, you should compile it and then create test methods as described below for the PentagonalPyramidTest class.

• PentagonalPyramidTest.java

Requirements: Create an PentagonalPyramidTest class that contains a set of test methods to test each of the methods in PentagonalPyramid.

Design: Typically, in each test method, you will need to create an instance of PentagonalPyramid, call the method you are testing, and then make an assertion about the expected result and the actual result (note that the actual result is commonly the result of invoking the method unless it has a void return type). You can think of a test method as simply formalizing or codifying what you have been doing in interactions to make sure a method is working correctly. That is, the sequence of statements that you would enter in interactions to test a method should be entered
into a single test method. You should have at least one test method for each method in PentagonalPyramid, except for associated getters and setters which can be tested in the same method. However, if a method contains conditional statements (e.g., an if statement) that results in more than one distinct outcome, you need a test method for each outcome. For example, if the method returns boolean, you should have one test method where the expected return value is false and another test method that expects the return value to be true (also, each condition in boolean expression must be exercised true and false). Collectively, these test methods are a set of test cases that can be invoked with a single click to test all of the methods in your PentagonalPyramid class.



• PentagonalPyramidList2.java (a modification of the PentagonalPyramidList2 class in the previous project; new requirements are underlined below.)

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

Design: The PentagonalPyramidList2 class has three fields, a constructor, and methods as outlined below.

(1) Fields (or instance variables): (1) a String representing the name of the list, (2) an array of PentagonalPyramid objects, and (3) an int representing the number of PentagonalPyramid objects in the PentagonalPyramid array. These are the only fields (or instance variables) that this class should have.
(2) Constructor: Your PentagonalPyramidList2 class must contain a constructor that accepts a parameter of type String representing the name of the list, a parameter of type PentagonalPyramid[], representing the list of PentagonalPyramid objects, and a parameter of type int representing the number of PentagonalPyramid objects in the PentagonalPyramid array. These parameters should be used to assign the fields described above (i.e., the instance variables).

(3) Methods: Methods: The methods for PentagonalPyramidList are described below. o getName: Returns a String representing the name of the list.
o numberOfPentagonalPyramids: Returns an int representing the number of PentagonalPyramid objects in the PentagonalPyramidList. If there are zero PentagonalPyramid objects in the list, zero should be returned.
o totalSurfaceArea: Returns a double representing the total surface areas for all PentagonalPyramid objects in the list. If there are zero PentagonalPyramid objects in the list, zero should be returned.
o totalVolume: Returns a double representing the total volumes for all
PentagonalPyramid objects in the list. If there are zero PentagonalPyramid objects in the list, zero should be returned.
o averageSurfaceArea: Returns a double representing the average surface area for all PentagonalPyramid objects in the list. If there are zero PentagonalPyramid objects in the list, zero should be returned.
o averageVolume: Returns a double representing the average volume for all
PentagonalPyramid objects in the list. If there are zero PentagonalPyramid 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 PentagonalPyramid in the array. In the process of creating the return result, this toString() method should include a while loop that calls the toString() method for each PentagonalPyramid 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 16 in the output from PentagonalPyramidListApp for the PentagonalPyramid_data_1.txt input file. [Note that the toString result should not include the summary items in lines 18 through 24 of the example. These lines represent the return value of the summaryInfo method.]
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 PentagonalPyramid objects, total surface area, total volume, average surface area, and average volume. Use "#,##0.0##" as the pattern to format the double values. For an example, see lines 18 through 24 in the output from PentagonalPyramidList2App for the PentagonalPyramid_data_1.txt input file. The second example shows the output from PentagonalPyramidList2App for the PentagonalPyramid_data_0.txt input file which contains a list name but no PentagonalPyramid data.
o getList: Returns the array of PentagonalPyramid 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 array of PentagonalPyramid objects, uses the list name, the array, and number of PentagonalPyramid objects in the array to create a
PentagonalPyramidList2 object, and then returns the PentagonalPyramidList2 object.
See note #1 under Important Considerations for the PentagonalPyramidList2MenuApp class (last page) to see how this method should be called.
o addPentagonalPyramid: Returns nothing but takes three parameters (label, base edge, and height), creates a new PentagonalPyramid object, and adds it to the PentagonalPyramidList2 object. Finally, the number of elements field must be incremented.
o findPentagonalPyramid: Takes a label of a PentagonalPyramid as the String parameter and returns the corresponding PentagonalPyramid object if found in the PentagonalPyramidList2 object; otherwise returns null. Case should be ignored when attempting to match the label.
o deletePentagonalPyramid: Takes a String as a parameter that represents the label of the PentagonalPyramid and returns the PentagonalPyramid if it is found in the PentagonalPyramidList2 object and deleted; otherwise returns null. Case should be ignored when attempting to match the label; consider calling/using
findPentagonalPyramid in this method. When an element is deleted from an array, elements to the right of the deleted element must be shifted to the left. After shifting the items to the left, the last PentagonalPyramid element in the array should be set to null. Finally, the number of elements field must be decremented.
o editPentagonalPyramid: Takes three parameters (label, base edge, and height), uses the label to find the corresponding the PentagonalPyramid object. If found, sets the base edge and height to the values passed in as parameters, and returns true. If not found, returns false. This method should not change the label.

New method for this project
o findPentagonalPyramidWithShortestBaseEdge: Returns the
PentagonalPyramid with the shortest baseEdge; if the list contains no PentagonalPyramid objects, returns null.
o findPentagonalPyramidWithLongestBaseEdge: Returns the
PentagonalPyramid with the longest baseEdge; if the list contains no PentagonalPyramid objects, returns null.
o findPentagonalPyramidWithSmallestVolume: Returns the
PentagonalPyramid with the smallest volume; if the list contains no PentagonalPyramid objects, returns null.
o findPentagonalPyramidWithLargestVolume: Returns the
PentagonalPyramid with the largest volume; if the list contains no PentagonalPyramid objects, returns null.

Code and Test: Remember to import java.util.Scanner, java.io.File, java.io.IOException. These classes will be needed in the readFile method which will require a throws clause for IOException.

• PentagonalPyramidList2Test.java

Requirements: Create an PentagonalPyramidList2Test class that contains a set of test methods to test each of the methods in PentagonalPyramidList2.

Design: Typically, in each test method, you will need to create an instance of
PentagonalPyramidList2, call the method you are testing, and then make an assertion about the expected result and the actual result (note that the actual result is usually the result of invoking the method unless it has a void return type). You can think of a test method as simply formalizing or codifying what you have been doing in interactions to make sure a method is working correctly. That is, the sequence of statements that you would enter in interactions to test a method should be entered into a single test method. You should have at least one test method for each method in PentagonalPyramidList2. However, if a method contains conditional statements (e.g., an if statement) that results in more than one distinct outcome, you need a test method for each outcome. For example, if the method returns boolean, you should have one test method where the expected return value is false and another test method that expects the return value to be true. Collectively, these test methods are a set of test cases that can be invoked with a single click to test all of the methods in your PentagonalPyramidList2 class.

PentagonalPyramidList2 toString method in one of your test cases so that Web-CAT will consider the toString method to be “covered” in its coverage analysis. Remember that you can set a breakpoint in a JUnit test method and run the test file in Debug mode. Then, when you have an instance in the Debug tab, you can unfold it to see its values or you can open a canvas window and drag items from the Debug tab onto the canvas.

Important: When comparing two arrays for equality in JUnit, be sure to use
Assert.assertArrayEquals rather than Assert.assertEquals. Assert.assertArrayEquals will return true only if the two arrays are the same length and the elements are equal based on an element by element comparison using the appropriate equals method.

Web-CAT

Assignment Part A – submit: PentagonalPyramid.java, PentagonalPyramidTest.java

Assignment Part B – submit: PentagonalPyramid.java, PentagonalPyramidTest.java, PentagonalPyramidList2.java, and PentagonalPyramidList2Test.java.
Note that data files PentagonalPyramid_data_1.txt and PentagonalPyramid_data_0.txt are available in
Web-CAT for you to use in your test methods. If you want to use your own data files, they should have a .txt extension, and they should be included with submission to Web-CAT (i.e., just add the .txt data file to your jGRASP project in the Source Files category).

Web-CAT will use the results of your test methods and their level of coverage of your source files as well as the results of our reference correctness tests to determine your grade.



More products