Sale!

Project: Ellipoid List2 Menu App

$35.00

Category:
5/5 - (2 votes)

Project: Ellipoid List2 Menu App Page 1 of 11
Page 1 of 11
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
much earlier. The skeleton code assignment is ungraded, but it checks that your classes and methods
are named correctly and that methods and parameters are correctly typed. 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 project, you must submit your completed 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
files in a zip file to your TA before the deadline.
Files to submit to Web-CAT (all three files must be submitted together):
• Ellipsoid.java
• EllipsoidList2.java
• EllipsoidList2MenuApp.java
Specifications – Use arrays in this project; ArrayLists are not allowed!
Overview: The objective is to modify your Project 6 to use arrays instead of ArrayList objects. You
will write a program this week that is composed of three classes: the first class defines Ellipsoid
objects, the second class defines EllipsoidList2 objects, and the third, EllipsoidList2MenuApp,
presents a menu to the user with eight options and implements these: (1) read input file (which creates
an EllipsoidList2 object), (2) print report, (3) print summary, (4) add an Ellipsoid object to the
EllipsoidList2 object, (5) delete an Ellipsoid object from the EllipsoidList2 object, (6) find an
Ellipsoid object in the EllipsoidList2 object, (7) Edit an Ellipsoid in the EllipsoidList2 object, and (8)
quit the program. [You should create a new “Project 7” folder and copy your Project 6 files
(Ellipsoid.java, EllipsoidList.java, Ellipsoid_data_1.txt, and Ellipsoid_data_0.txt) to it, rather than
work in the same folder as Project 6 files.]
To rename an existing .java file, open the file in jGRASP, change the name of the class
and the name of the constructor (if it has one) in the source file, and then click the Save button.
In the dialog that pops up, click the “Rename and Save” button. This will rename and save the
.java file and delete the old associated .class file.
• Ellipsoid.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 EllipsoidList2.java on page 4.
Otherwise, you will need to create Ellipsoid.java as part of this project.)
Requirements: Create an Ellipsoid class that stores the label and three axes a, b, and c. The
values of the axes must be greater than zero. The Ellipsoid class also includes methods to set and
get each of these fields, as well as methods to calculate the volume and surface area of the
Ellipsoid object, and a method to provide a String value of an Ellipsoid object (i.e., a class
instance).
Project: Ellipoid List2 Menu App Page 2 of 11
Page 2 of 11
An Ellipsoid is a 3-D object whose plane sections are ellipses defined by three axes (a, b, c) as depicted
below. The formulas are provided to assist you in computing return values for the respective methods in
the Ellipsoid class described in this project.
Formulas for volume (V) and surface area
(S) are shown below.
� =
4����
3
Design: The Ellipsoid class has fields, a constructor, and methods as outlined below.
(1) Fields (instance variables): label of type String, and axes a, b, and c of type double. Initialize
the String variable to “” and the double variables to 0 in their respective declarations. These
instance variables should be private so that they are not directly accessible from outside of the
Ellipsoid class, and these should be the only instance variables (i.e., fields) in the class.
(2) Constructor: Your Ellipsoid class must contain a public constructor that accepts four
parameters (see types of above) representing the label, a, b, and c. 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 Ellipsoid 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.
Ellipsoid ex1 = new Ellipsoid (“Ex 1″, 1, 2, 3);
Ellipsoid ex2 = new Ellipsoid (” Ex 2 “, 2.3, 5.5, 7.4);
Ellipsoid ex3 = new Ellipsoid (“Ex 3”, 123.4, 234.5, 345.6);
(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 Ellipsoid, 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.
Project: Ellipoid List2 Menu App Page 3 of 11
Page 3 of 11
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 getA: Accepts no parameters and returns a double representing field a.
o setA: Accepts a double parameter and returns a boolean as follows. If the double is
greater than zero, sets field a to the double passed in and returns true. Otherwise, the
method returns false and does not set the field.
o getB: Accepts no parameters and returns a double representing field b.
o setB: Accepts a double parameter and returns a boolean as follows. If the double is
greater than zero, sets field b to the double passed in and returns true. Otherwise, the
method returns false and does not set the field.
o getC: Accepts no parameters and returns a double representing field c.
o setC: Accepts a double parameter and returns a boolean as follows. If the double is
greater than zero, sets field c to the double passed in and returns true. Otherwise, the
method returns false and does not set the field.
o volume: Accepts no parameters and returns the double value for the volume calculated
using formula above and the values of axes fields a, b, c.
o surfaceArea: Accepts no parameters and returns the double value for the surface
area calculated using formula above and the values of axes fields a, b, c.
o toString: Returns a String containing the information about the Ellipsoid 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:
volume()and surfaceArea(). Each line should have no trailing spaces (e.g., there
should be no spaces before a newline (\n) character). The toString value for ex1, ex2,
and ex3 respectively are shown below (the blank lines are not part of the toString
values).
Ellipsoid “Ex 1” with axes a = 1.0, b = 2.0, c = 3.0 units has:
volume = 25.1327 cubic units
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, c = 345.6 units has:
volume = 41,890,963.5508 cubic units
surface area = 674,164.7034 square units
Code and Test: As you implement your Ellipsoid 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 Ellipsoid in interactions (e.g., copy/paste the examples
above on page 2). Remember that when you have an instance on the workbench, you can unfold
it to see its values. You can also open a viewer canvas window and drag the instance from the
Project: Ellipoid List2 Menu App Page 4 of 11
Page 4 of 11
Workbench tab to the canvas window. After you have implemented and compiled one or more
methods, create an Ellipsoid 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 Ellipsoid then prints it out. This would be
similar to the EllipsoidApp class from a previous project, except that in the EllipsoidApp class
you read in the values and then create and print the object.
• EllipsoidList2.java – You must use arrays instead of ArrayList objects. (Assuming that you
successfully created this class in the previous project, just copy EllipsoidList.java to your
new Project 7 folder. Otherwise, you will need to create all of EllipsoidList2.java as part of
this project. To rename the existing .java file to EllipsoidList2, open the file in jGRASP,
change the name of the class and the name of the constructor in the source code, and then
click the Save button. In the dialog that pops up, click the “Rename and Save” button.
This will rename and save the .java file and then delete old associated .class file). In the
requirements below, EllipsoidList has been changed to EllipsoidList2. Be sure to make these
changes in your methods as necessary.
Requirements: Create an EllipsoidList2 class that stores the name of the list and an array of
Ellipsoid objects, and the number of Ellipsoid objects in the array. It also includes methods that
return the name of the list, number of Ellipsoid objects in the EllipsoidList2, total volume, total
surface area, average volume, and average surface for all Ellipsoid objects in the EllipsoidList2.
The toString method returns a String containing the name of the list followed by each Ellipsoid in
the array, and a summaryInfo method returns summary information about the list (see below).
Design: The EllipsoidList2 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
Ellipsoid objects, and (3) an int representing the number of Ellipsoid objects in the
Ellipsoid array. These are the only fields (or instance variables) that this class should have.
(2) Constructor: Your EllipsoidList2 class must contain a constructor that accepts a parameter
of type String representing the name of the list, a parameter of type Ellipsoid[],
representing the list of Ellipsoid objects, and a parameter of type int representing the
number of Ellipsoid objects in the Ellipsoid array. These parameters should be used to assign
the fields described above (i.e., the instance variables).
(3) Methods: Methods: The methods for EllipsoidList2 are described below.
o getName: Returns a String representing the name of the list.
o numberOfEllipsoids: Returns an int representing the number of Ellipsoid objects
in the list. If there are zero Ellipsoid objects in the list, zero should be returned.
o totalVolume: Returns a double representing the total volume for all Ellipsoid objects
in the list. If there are zero Ellipsoid objects in the list, zero should be returned.
o totalSurfaceArea: Returns a double representing the total surface area for all
Ellipsoid objects in the list. If there are zero Ellipsoid objects in the list, zero should be
returned.
Project: Ellipoid List2 Menu App Page 5 of 11
Page 5 of 11
o averageVolume: Returns a double representing the average volume for all Ellipsoid
objects in the list. If there are zero Ellipsoid objects in the list, zero should be returned.
o averageSurfaceArea: Returns a double representing the average surface area for
all Ellipsoid objects in the list. If there are zero Ellipsoid objects in the list, zero should
be returned.
o toString: Returns a String (does not begin with \n) containing the name of the list
followed by each Ellipsoid in the list. In the process of creating the return result, this
toString() method should include a while loop that calls the toString() method for each
Ellipsoid object in the list (adding a \n before and after each). Be sure to include
appropriate newline escape sequences. For an example, in the previous project see lines
3 through 16 in the output below from EllipsoidListApp for the Ellipsoid_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 below.]
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) followed by various
summary items: number of Ellipsoid objects, total volume, total surface area, average
volume, and average surface area. Use “#,##0.0##” as the pattern to format the double
values. For an example, in the previous project see lines 18 through 24 in the output
below from EllipsoidListApp for the Ellipsoid_data_1.txt input file. The second example
below shows the output from EllipsoidListApp for the Ellipsoid_data_0.txt input file
which contains a list name but no Ellipsoid data.
o getList: Returns the array of Ellipsoid objects (the second field above).
o readFile: Takes a String parameter representing the file name, creates an array of
Ellipsoid objects with length of 100, reads in the file, storing the list name and creating
Ellipsoid objects, adding them to the Ellipsoid array, then uses the list name, the array,
and number of Ellipsoid objects in the array to create an EllipsoidList2 object, and finally
returns the EllipsoidList2 object. See note #1 under Important Considerations for the
EllipsoidList2MenuApp 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 object, and adds it to the EllipsoidList2 object. Finally, the number of
Ellipsoid objects field must be incremented.
o findEllipsoid: Takes a label of an Ellipsoid as the String parameter and returns the
corresponding Ellipsoid object if found in the EllipsoidList2 object; otherwise returns
null. Case should be ignored when attempting to match the label.
o deleteEllipsoid: Takes a String as a parameter that represents the label of the
Ellipsoid and returns the Ellipsoid if it is found in the EllipsoidList2 object and deleted;
otherwise returns null. Case should be ignored when attempting to match the label;
consider calling/using findEllipsoid 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 Ellipsoid element in the array should be set to
null. Finally, the number of Ellipsoid objects field must be decremented.
o editEllipsoid: 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.
Project: Ellipoid List2 Menu App Page 6 of 11
Page 6 of 11
Code and Test: Remember to import 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 go through the objects in the array. 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 the
EllipsoidList2MenuApp class.
• EllipsoidList2MenuApp.java (replaces EllipsoidConeListMenuApp class from the previous
project; the file and class name in the file must be renamed to reflect EllipsoidList2MenuApp).
To rename an existing .java file, open the file in jGRASP, change the name of the class in
the source code, and then click the Save button. In the dialog that pops up, click the
“Rename and Save” button. This will rename the .java file, save it, and delete the old
associated .class file. Be sure to make these changes in your main method as necessary.
Requirements: Create an EllipsoidList2MenuApp 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 EllipsoidList2 object, (2) print the EllipsoidList2 object, (3) print the
summary for the EllipsoidList2 object, (4) add an Ellipsoid object to the EllipsoidList2 object, (5)
delete an Ellipsoid object from the EllipsoidList2 object, (6) find an Ellipsoid object in the
EllipsoidList2 object, (7) edit an Ellipsoid object in the EllipsoidList2 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 an
EllipsoidList2 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 select.
Project: Ellipoid List2 Menu App Page 7 of 11
Page 7 of 11
Line # Program output
1
2
3
4
5
6
7
8
9
10
Ellipsoid List System Menu
R – Read File and Create Ellipsoid List
P – Print Ellipsoid List
S – Print Summary
A – Add Ellipsoid
D – Delete Ellipsoid
F – Find Ellipsoid
E – Edit Ellipsoid
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 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_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: Ellipsoid_data_1.txt
File read in and Ellipsoid List created
Enter Code [R, P, S, A, D, F, E, or Q]:
The result of the user selecting ‘p’ to Print Ellipsoid 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
Enter Code [R, P, S, A, D, F, E, or Q]: p
Ellipsoid Test List
Ellipsoid “Ex 1” with axes a = 1.0, b = 2.0, c = 3.0 units has:
volume = 25.1327 cubic units
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, c = 345.6 units has:
volume = 41,890,963.5508 cubic units
surface area = 674,164.7034 square units
Enter Code [R, P, S, A, D, F, E, or Q]:
Project: Ellipoid List2 Menu App Page 8 of 11
Page 8 of 11
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
Enter Code [R, P, S, A, D, F, E, or Q]: s
—– Summary for Ellipsoid Test List —–
Number of Ellipsoid Objects: 3
Total Volume: 41,891,380.796 cubic units
Total Surface Area: 674,531.564 square units
Average Volume: 13,963,793.599 cubic units
Average Surface Area: 224,843.855 square units
Enter Code [R, P, S, A, D, F, E, or Q]:
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
2
3
4
5
6
7
8
Enter Code [R, P, S, A, D, F, E, or Q]: a
label: Ex 4
a: 10.2
b: 12.4
c: 14.6
*** Ellipsoid added ***
Enter Code [R, P, S, A, D, F, E, or Q]:
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; 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 3
“Ex 3” deleted
Enter Code [R, P, S, A, D, F, E, or Q]: d
label: ex 17
“ex 17” not found
Enter Code [R, P, S, A, D, F, E, or Q]:
Project: Ellipoid List2 Menu App Page 9 of 11
Page 9 of 11
Here is an example of the successful “find” for an Ellipsoid object, followed by an attempt that
was not successful (i.e., the Ellipsoid object was not found).
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]: f
label: ex 2
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
Enter Code [R, P, S, A, D, F, E, or Q]: f
label: ex 7
“ex 7” not found
Enter Code [R, P, S, A, D, F, E, or Q]:
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 “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
10
11
12
13
14
15
Enter Code [R, P, S, A, D, F, E, or Q]: e
label: ex 2
a: 4.6
b: 11.0
c: 14.8
“Ex 2” successfully edited
Enter Code [R, P, S, A, D, F, E, or Q]: e
label: ex 13
a: 12
b: 13
c: 14
“ex 13” 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]: b
*** invalid code ***
Enter Code [R, P, S, A, D, F, E, or Q]: q
Project: Ellipoid List2 Menu App Page 10 of 11
Page 10 of 11
Code and Test:
Important considerations: This class should import java.util.Scanner 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 array of Ellipsoid
objects and then declare and create an EllipsoidList2 object using the list name, the array, and
0 as the parameters in the constructor. This will be an EllipsoidList2 object that contains no
Ellipsoid objects. For example:
String _______ = “*** no list name assigned ***”;
Ellipsoid[] _________ = new Ellipsoid[100];
EllipsoidList2 _________ = new EllipsoidList2(_________,_________,_________);
The ‘R’ option in the menu should invoke the readFile method on your EllipsoidList2 object.
This will return a new EllipsoidList2 object based on the data read from the file, and this new
EllipsoidList2 object should replace (be assigned to) your original EllipsoidList2 object
variable in main. Since the readFile method throws FileNotFoundException, your main
method needs to do this as well.
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.
After printing the menu of actions with descriptions, you should have a do-while loop that prints
the prompt with just the action codes followed by a switch statement that performs the indicated
action. The do-while loop ends when the user enters ‘q’ to quit. You should strongly consider
using a for-each loop as appropriate in the new methods that require you to search the list. You
should be able to test your program by exercising each of the action codes. After you implement
the “Print Ellipsoid List” option, you should be able to print the EllipsoidList2 object after
operations such as ‘A’ and ‘D’ to see if they worked. You may also want to run in debug mode
with a breakpoint set at the switch statement so that you can step-into your methods if something
is not working. In conjunction with running the debugger, you should also create a canvas drag
the items of interest (e.g., the Scanner on the file, your EllipsoidList2 object, etc.) onto the canvas
and save it. As you play or step through your program, you’ll be able to see the state of these
objects change when the ‘R’, ‘A’, and ‘D’ options are selected.
a. For option P, when you print the EllipsoidList2 object (e.g., myList) be sure to
append a leading “\n” in println:
System.out.println(“\n” + myList);
Project: Ellipoid List2 Menu App Page 11 of 11
Page 11 of 11
b. For option S, when you print the summary for EllipsoidList2 object (e.g., cList) be
sure to append a leading and trailing “\n” in the println:
System.out.println(“\n” + myList.summaryInfo() + “\n”);
Although your program may not use all of the methods in your Ellipsoid and EllipsoidList2
classes, you should ensure that all of your methods work according to the specification. You can
run your program in the canvas and then after the file has been read in, you can call methods on
the EllipsoidList2 object in interactions or you can write another class and main method to
exercise the methods. Web-CAT will test all methods to determine your project grade.

PlaceholderProject: Ellipoid List2 Menu App
$35.00
Open chat
Need help?
Hello
Can we help?