final
class Parallelogram as follows (this is a partial credit assignment
for up to 7½ out of ten (10) points):
this
constructor with default values for the data fields all of which
are zero (0)
super
class constructor for the
x and y fields and the set
methods of this class for side1, side2 and
angle
()
method that returns the value
of the other angle of the parallelogram which is calculated as 180
minus the first angle
()
that overrides the
abstract
method in Shape and that prints the
two sides and two angles of the parallelogram (preceded by the position of
the Shape object) to the terminal window in the format:
Position at x = 20, y = 0
Draw parallelogram with sides 10 by 15 and angles 60 degrees and 120 degrees
()
method in the "Shapes.java"
class file to instantiate a fourth element to the s array from the
Parallelogram constructor
- 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
@parameter
and@return
tags
abstract
superclass and two final
subclasses) and an interface file as per the
following specifications (this is the full credit assignment for up to 10
out of ten (10) points):
Employee superclass to Salesperson and Executive
|
Salesperson extends from Employee implements SalaryConstants
|
—and— |
Executive extends from Employee implements SalaryConstants
|
—Write both the Salesman and Executive subclasses— |
- Specifications for
abstract
superclass Employee:
- The class should have one constructor that takes three arguments, one for each of its attributes, and passes those values to the set methods
- A set method for each of the three instance variables; follow validation rules for the salary attribute (see above) and
throw
anException
for invalid data- A get method for each of the three instance variables
- An
abstract
method getAdditionalIncome()
of typedouble
- Method getTotalSalary
()
of typedouble
that returns the sum of the salary attribute and the return value of the getAdditionalIncome()
method (see SalesPerson and Executive class descriptions below) of its subclasses- Method
toString()
returns a "string representation of an Employee object with values preceded by descriptive labels as follows: (a) each of the three instance variables; and (b) the return value from the getTotalSalary()
method
- Specifications for
final
subclass Salesperson:
- The class should have two constructors: (a) one that takes no arguments and passes the default values to the second constructor via the
this
reference; and (b) another that takes four arguments, one its own sales attribute and the three others for its superclass; it passes the three arguments to the superclass' constructor and passes the sales argument to to its own set method- A set method for the sales instance variable; follow validation rules in the set method (see above) and
throw
anException
for invalid data- A get method for the sales instance variable
- Method getAdditionalIncome
()
of typedouble
that "implements" theabstract
method from superclass Employee and returns a salesperson's commission which is calculated by multiplying the sales attribute times the sales commission rate constant that comes from the SalaryConstants interface (see below)- There is no
toString()
method since output for the commission is handled in thetoString()
method of the superclass
- Specifications for
final
subclass Executive:
- The class should have two constructors: (a) one that takes no arguments and passes the default values to the second constructor via the
this
reference; and (b) another that takes three arguments which it passes to the superclass constructor- Method getAdditionalIncome
()
of typedouble
that "implements" theabstract
method from superclass Employee and returns a executive's bonus which is calculated by multiplying the salary attribute from the superclass Employee times the bonus rate constant that comes from the SalaryConstants interface (see below)- There is no
toString()
method since output for the bonus is handled in thetoString()
method of the superclass
- In the interface SalaryConstants define the following constants:
- COMMISSION_RATE of type
double
assigned the value 0.15 (15%)- BONUS_RATE of type
double
assigned the value 0.40 (40%)
- Write a driver class similar to "Shapes1.java" from the Chapter 15 lectures that instantiates one object from each subclass, Salesperson and Executive, and displays the return value of the toString
()
method of the objects using eitherSystem.out.println()
orJOptionPane.showMessageDialog()
(8½ points maximum)
- Write a driver class similar to "Shapes2.java" from the Chapter 15 lectures that instantiates one object from each subclass (Salesperson and Executive) as array objects of
super
type Employee using subtyping, and iterates through the array elements to display the return value of thetoString()
method of the objects using eitherSystem.out.println()
orJOptionPane.showMessageDialog()
(9 points maximum)
- Full credit Write a driver class that instantiates one object from each subclass (Salesperson and Executive) as array objects of
super
type Employee using subtyping calling their no-parameter constructors; then iterate through the array of objects to input values for each of the four fields using either aScanner
object orJOptionPane.showInputDialog()
(and an appropriate parse method for numeric fields) and pass the input values to the set methods of each of the instance variables- It will be necessary to use Java's
instanceof
operator for the Salesperson object to get input from the user only for the sales field of this object and not Executive; in addition it will be necessary in the call to the set method for sales to cast the object to type Salesperson as per the following:
( (Salesperson) employee[index] )
- Still inside the loop call the toString
()
method of both objects to display the values using using eitherSystem.out.println()
orJOptionPane.showMessageDialog()
(10 points maximum)
- Including a substantive comment statement that describes the class's or interface'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 each new class
- Entering a substantive comment before each method (including the constructor) to describe its function along with
@parameter
,@return
and@throws
tags