Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I require assistance with the follow example project (I had made a project but it wouldn't test properly): SpherocylinderList.java (new for Part 3) -

Hello, I require assistance with the follow example project (I had made a project but it wouldn't test properly):

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
SpherocylinderList.java (new for Part 3) - Consider implementing this file in parallel with its test file, SpherocylinderListTest.java, which is described after this class. Requirements: Create a SpherocylinderList class that stores the name of the list and an array of Spherocylinder objects. It also includes methods that return the name of the list, number of Spherocylinder objects in the SpherocylinderList, total surface area, total volume, average surface area, and average volume for all Spherocylinder objects in the SpherocylinderList. The toString method returns summary information about the list (see below). Design: The SpherocylinderList 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 Spherocylinder objects, and (3) an int representing the number of Spherocylinder objects in the array. Note that the number of Spherocylinder objects may be less than the length of the array. These are the only fields (or instance variables) that this class should have.(2) Constructor: Your SpherocylinderList class must contain a constructor that accepts three parameters: (1) a parameter of type String representing the name of the list, (2) a parameter of type Spherocylinder , representing the list of Spherocylinder objects, and (3) a parameter of type int representing the number of Spherocylinder objects in the array. These parameters should be used to assign the fields described above (i.e., the instance variables). (3) Methods: The methods for SpherocylinderList are described below. o getName: Returns a String representing the name of the list. O numberOfSpherocylinders: Returns an int representing the number of Spherocylinder objects in the SpherocylinderList. If there are zero Spherocylinder objects in the list, zero should be returned. o totalSurfaceArea: Returns a double representing the total surface areas for all Spherocylinder objects in the list. If there are zero Spherocylinder objects in the list, zero should be returned. O totalVolume: Returns a double representing the total volumes for all Spherocylinder objects in the list. If there are zero Spherocylinder objects in the list, zero should be returned. O averageSurfaceArea: Returns a double representing the average surface area for all Spherocylinder objects in the list. If there are zero Spherocylinder objects in the list, zero should be returned. O averageVolume: Returns a double representing the average volume for all Spherocylinder objects in the list. If there are zero Spherocylinder objects in the list, zero should be returned. toString: Returns a String (does not begin with \ ) containing the name of the list (which can change depending of the value for name passed in to the constructor) followed by various summary items: number of Spherocylinders, total surface area, total volume, average surface area, and average volume. Use "#,##0.0##" as the pattern to format the double values. Below is an example of the formatted String returned by the toString method, where the name of the list (name field) is Spherocylinder Test List and the array of Spherocylinder objects contains the three examples described above (bottom of page 2). --- Summary for Spherocylinder Test List Number of Spherocylinders: 3 Total Surface Area: 184, 790. 426 Total Volume: 6,996,733. 041 Average Surface Area: 61, 596. 809 Average Volume: 2, 332 , 244.347 O getList: Returns the array of Spherocylinder objects (the second field above). o addSpherocylinder: Returns nothing but takes three parameters (label, radius, and cylinder height), creates a new Spherocylinder object, and adds it to the SpherocylinderList object. Be sure to increment the int field containing the number of Spherocylinder objects in the SpherocylinderList object. o findSpherocylinder: Takes a label of a Spherocylinder as the String parameter and returns the corresponding Spherocylinder object if found in the SpherocylinderList object; otherwise returns null. Case should be ignored when attempting to match the labelo deleteSpherocylinder: Takes a String as a parameter that represents the label of the Spherocylinder and returns the Spherocylinder if it is found in the SpherocylinderList object and deleted; otherwise returns null. Case should be ignored when attempting to match the label. 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 Spherocylinder element in the array should be set to null. Finally, the number of elements field must be decremented. o editSpherocylinder: Takes three parameters (label, radius, and cylinder height), uses the label to find the corresponding the Spherocylinder object in the list. If found, sets the radius and cylinder height to the values passed in as parameters, and returns true. If not found, returns false. o findSpherocylinderWithLargestVolume : Returns the Spherocylinder with the largest volume: if the list contains no Spherocylinder objects, returns null. Code and Test: Some of the methods above require that you use a loop to go through the objects in the array. You should 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 test method in the test file described below. SpherocylinderListTest.java (new for Part 3) - Consider implementing this file in parallel with its source file, SpherocylinderList.java, which is described above this class. Requirements: Create a SpherocylinderListTest class that contains a set of test methods to test each of the methods in SpherocylinderList. Design: Typically, in each test method, you will need to create an instance of SpherocylinderList, 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 SpherocylinderList. 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 SpherocylinderList class. Code and Test: A good strategy would be to begin by writing test methods for those methods in SpherocylinderList that you "know" are correct. By doing this, you will be able to concentrate on the getting the test methods correct. That is, if the test method fails, it is most likely due to a defect in the test method itself rather the SpherocylinderList method being testing. As you become more familiar with the process of writing test methods, you will be better ed towrite the test methods for the new methods in SpherocylinderList. Be sure to call the SpherocylinderList toString method in one of your test cases so that the grading system will consider the toString method to be "covered" in its coverage analysis. Remember that when a test method fails, 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. You can also step-in to the method being called by the test method and then single-step through it, looking for the error. Finally, when comparing two arrays for equality in JUnit, be sure to use Assert. assertArray Equals 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 equals method

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions