()
method for a maximum
grade of eight (8) out of ten possible points)
- Start a new Java project named "project-4" and copy into it the SimpleGeometricObject class from Listing 11.1 in the textbook (this class should be renamed GeometricObject) which should be modified as follows
- Do not assign values to the
private
instance variables when they are declared- The only statement in the no-argument constructor is a call to the
this
constructor with default data field values "white" for color andfalse
for filled- The overloaded constructor that takes a
String
for color and aboolean
for filled still instantiates and initializes the dateCreated field but initializes the color and filled fields by calling their set methods- The
toString()
method substitutes calls to the get methods rather than directly accessing the three instance variables directly
- Modify the assignment as follows:
- The no-parameter constructor only contains a call to the
this
constructor and passes the default values 1.0 to the overloaded constructor that takes threedouble
parameters- The constructor that creates a triangle with the specified side1, side2 and side3 parameters does so by calling the three set methods; all three set methods should validate that each side is 1.0 or greater
- In the getArea
()
method calculate and return the area of a triangle using "Heron's Formula" given that the length of the three sides is known; the formula can be found by doing an Internet search- The
toString()
method substitutes calls to the get methods rather than directly accessing the three instance variables and further returns the values from the getPerimeter()
and getArea()
(unless you choose not to calculate the area--see above) methods; additionally link this method to thetoString()
method of the superclass to produce output similar to the following (format the getArea()
and getPerimeter()
method return values rounding them to two decimals using aDecimalFormat
object):
Triangle: side1 = 12.0 side2 = 15.0 side3 = 25.0
area: 63.28 perimeter: 52.00
created on Mon Oct 14 15:30:01 EDT 2013
color: white and filled: false- Create a new class
Main
and add amain()
method that should instantiate two objects, one from each of the two constructors, and display thetoString()
method return value with eitherSystem.out.println()
orJOptionPane.showMessageDialog()
- In BlueJ open the Java project named "college" which you downloaded with the "Chapter 11" files from the instructor's website and which already contains the follow class:
CommunityMember superclass to Student
|
- Then create two class files, a superclass and a subclass, as per the following specifications:
Studentextends from CommunityMembersuperclass to Undergraduate and Graduate
|
Undergraduateextends from Student
|
--or-- |
Graduateextends from Student
|
--Write either the Undergraduate or Graduate subclass, not both-- |
- Both the superclass (Student) and the subclass (either Undergraduate or Graduate) will contain two instance variables (data fields) so that effectively:
- The Student class will have four fields (firstName and lastName which it inherits from CommunityMember, and the two of its own, studentID and gradePointAverage
- The Undergraduate or Graduate will have six fields (firstName and lastName which it inherits indirectly from CommunityMember, studentID and gradePointAverage which it inherits from Student, and the two of its own, either satScore and classYear for Undergraduate, or greScore and program for Graduate
- The constructors for the new classes are as follows:
- The superclass/subclass Student has a single constructor that takes four parameters, two of which it passes immediately to its superclass constructor CommunityMember that takes two parameters
- The subclasses, either Undergraduate or Graduate, include two constructors: a no-parameter constructor that passes default values (zero (0) for numerics and empty strings for
String
variables) to thethis()
constructor and a constructor that takes six parameters, four of which it passes immediately to the superclass constructor of Student that takes four parameters
- All classes should have set methods that contain
if
validation coding based on the validation rules defined above (there should be a default value for each data field, zero (0) for numerics and empty strings forString
variables, to indicate any value is not set) and a get method for each of its instance variables
- All classes should contain a
toString()
method that is a formatted "string" representation of the object with all field values and appropriate labels, and which calls (links to) thetoString()
method of its superclass
- Including a substantive comment statement that describes the class's purpose, as well as substituting your name for the existing
@author
comment and the assignment due date for the@version
comment that already exist at the top of the new class- Entering a substantive comment before each method (including the constructor) to describe its function along with
@param
and@return
tags
main()
method to it
that includes the test operations as follows:showInputDialog()
method of class JOptionPane
along with appropriate parse methods when necessary to get values to
pass to the set methods of the object; display the return value of
the object's toString()
method in a showMessageDialog()
()
method in another showMessageDialog()
main()
method