$30
Project: Ellipsoid App Page 1 of 5
Page 1 of 5
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 (both files must be submitted together):
• Ellipsoid.java
• EllipsoidApp.java
Specifications
Overview: You will write a program this week that is composed of two classes: (1) one named
Ellipsoid that defines Ellipsoid objects, and (2) the other, EllipsoidApp, which has a main method that
reads in data, creates an Ellipsoid object, and then prints the object.
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
• Ellipsoid.java
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: Ellipsoid App Page 2 of 5
Page 2 of 5
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.
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.
Project: Ellipsoid App Page 3 of 5
Page 3 of 5
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 square units
surface area = 48.9366 cubic units
Ellipsoid "Ex 2" with axes a = 2.3, b = 5.5, c = 7.4 units has:
volume = 392.1127 square units
surface area = 317.9245 cubic units
Ellipsoid "Ex 3" with axes a = 123.4, b = 234.5, c = 345.6 units has:
volume = 41,890,963.5508 square units
surface area = 674,164.7034 cubic 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
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 you will create below, except that in the EllipsoidApp class you
will read in the values and then create and print the object.
• EllipsoidApp.java
Requirements: Create an EllipsoidApp class with a main method that reads in values for label
and the axes a, b, and c. After the values have been read in, the main method creates an Ellipsoid
object and then prints a new line and the object.
Design: The main method should prompt the user to enter the label, a, b, and c. After each axis
value is read in, if the value is less than or equal to zero, an appropriate message (see examples
below) should be printed followed by a return from main. Assuming a, b, and c are positive, an
Ellipsoid object should be created and printed.
Project: Ellipsoid App Page 4 of 5
Page 4 of 5
Below are examples where the user has entered a non-positive value for each axes a, b, c. Your
program input/output should be exactly as follows.
Line # Program input/output
1
2
3
4
5
Enter label and axes a, b, c for an ellipsoid.
label: bad value for a
a: -1
Error: axis value must be positive.
Line # Program input/output
1
2
3
4
5
6
Enter label and axes a, b, c for an ellipsoid.
label: bad value for b
a: 1
b: 0
Error: axis value must be positive.
Line # Program input/output
1
2
3
4
5
6
Enter label and axes a, b, c for an ellipsoid.
label: bad value for c
a: 12.5
b: 10.1
c: -8.4
Error: axis value must be positive.
Below is an example where the user has the values from ex1, the first example, above for label, a,
b, and c. Your program input/output should be exactly as follows.
Line # Program input/output
1
2
3
4
5
6
7
8
9
Enter label and axes a, b, c for an ellipsoid.
label: Ex 1
a: 1.0
b: 2.0
c: 3.0
Ellipsoid "Ex 1" with axes a = 1.0, b = 2.0, c = 3.0 units has:
volume = 25.1327 square units
surface area = 48.9366 cubic units
Code: Your program should use the nextLine method of the Scanner class to read user input.
Note that this method returns the input as a String. Whenever necessary, you can use the
Double.parseDouble method to convert the input String to a double. For example:
Double.parseDouble(s1) will return the double value represented by String s1. For the
printed lines requesting input for label, a, b, and c, use a tab "\t" rather than three spaces. After
you have created the object, it can be printed simply by using its variable name; i.e., when the
object’s variable name is evaluated in the println statement, its toString() method is
automatically called. Thus, printing the object reference variable myObj is equivalent to printing
the return value of the myObj.toString() method call. In your println statement, be sure to
prepend the newline character (e.g., "\n" + myObj) to skip the line as shown in the examples.
Project: Ellipsoid App Page 5 of 5
Page 5 of 5
Test: You should test several sets of data to make sure that your program is working correctly.
Although your main method may not use all the methods in Ellipsoid, you should ensure that all
of your methods work according to the specification. You can use interactions in jGRASP or you
can write another class and main method to exercise the methods. The viewer canvas should also
be helpful, especially using the “Basic” viewer and the “toString” viewer for an Ellipsoid object.
Web-CAT will test all of the methods specified above for Ellipsoid to determine your project
grade.
General Notes
1. All input from the keyboard and all output to the screen should done in the main method. Only one
Scanner object on System.in should be created and this should in the main method. All printing (i.e.,
using the System.out.print and System.out.println methods) should be in the main method. Hence,
none of your methods in the Ellipsoid class should do any input/output (I/O).
2. When a method has a return value, you can ignore the return value if it is no interest in the current
context. For example, when setA(3.5) is invoked, it returns true to let the caller know field a was set;
whereas setA(-3.5) will return false indicating field a was not set. If the caller knows that x is
positive, then the return value of setA(x) can safely be ignored since it can be assumed to be true.
3. Even though your main method (or other methods) may not be using the return value of a method
such as setA(x), you can ensure that the return type is correct by using interactions.