CPSC 233: Mini-Assignment #4
Due Oct 2 at 4 PM
New Concepts to be applied for the assignment
- Inheritance
- Method overriding & polymorphism
- Implementing a solution within a specific framework (predefined parent
and method calls specified)
Overview
You must work with the starting code provided in class
Animal and the Driver
class. You cannot change the code in these classes and you cannot write your own
versions. The source code can be found in the course directory under:
/home/233/assignments/mini_assignment4/code
Class Animal
is the parent class whose functionality you will extend by implementing the
child class:
Bird. The new
capabilities of the child should be accessible using the series of method calls specified in
the Driver class (aBird
refers to a 'Bird' object)
System.out.println(aBird);
// Display initial state (two attributes)
aBird.fly();
// Reduce energy by the specified amount, display
message
aBird.walk();
// Reduce energy by the specified amount, display
message
System.out.println(aBird);
// Display new state (two attributes)
In order to receive credit you not only have to implement the features of
class Bird (specified below) but the 4 method calls
in the Driver class must correctly work.
Features of class Bird
Everyone starts with a grade point of zero for this assignment. Implementing
each of the features below completely and correctly will award you
1.0 grade points (i.e. implementing all four features
will result in a grade point of 4.0 being awarded).
- Class Bird is defined as a child of
the
Animal class with a new integer attribute 'range'
which is set to a default value of 400.
|
- Override the walk() method that
will display an output message that is different from the
message in the walk()
implemented in the Animal class and
reduces energy by 3 points.
|
- Implement a fly() method that will
display a clear and unique output message and reduces energy by 2
points.
|
- Override the toString() method.
Unlike the walk() method above, this
overridden method will use the existing functionality of the
toString() method in the
Animal class, in this case to return
the state of the 'energy' attribute
i.e. the child toString() method calls
the parent toString() for the state of
the parent's attribute. The child toString()
method concatentates onto the parent object's state the state of the
child (state of the 'range' attribute)
and returns this new string back to its caller.
|
Sample output
There's a sample output file in the course directory under:
/home/233/assignments/mini_assignment4/output
Submitting your work:
- Assignments (source code/'dot-java' file) must be electronically
submitted according to [the assignment submission requirements]
using [D2L].
Although you can assume that TAs have access to the two predefined classes
submitting them with the Bird class will make
marking easier. (D2L bundles all your submitted files into a zip document
and when the document is uncompressed all three source code files will be
placed into a separate directory one for each student).
- As a reminder, you are not allowed to work in groups for this class.
Copying the work of another student will be
regarded as academic misconduct (cheating). For additional details about
what is and is not okay for this class please refer to the following
[link].
External libraries that can be used (unless otherwise you can not assume
that you can use the library).
- You cannot use methods other than the ones for output:
printf(), print(),
println(). There's no need for input for this
assignment.