Course web page: Introduction to Computer Science for non-majors II James Tam Return to the course web page

CPSC 219: Mini-Assignment #3

Due Thur Mar 10 at 4 PM

New Concepts to be applied for the assignment

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/219/assignments/mini_assignment4/code [Web Shortcut to the starting 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/219/assignments/mini_assignment4/output. [Web Shortcut to the output]

Using pre-written Java code

You cannot use methods other than the ones for output: printf(), print(), println(). There's no need for input for this assignment.

Points to keep in mind:

  1. Due time: All assignments are due at 4 PM on the due dates listed on the course web page.  Late assignments or components of assignments will not be accepted for marking without approval for an extension beforehand. What you have submitted in D2L as of the due date is what will be marked.
  2. Extensions may be granted for reasonable cases by the course instructor with the receipt of the appropriate documentation (e.g., a doctor's note). Typical examples of reasonable cases for an extension include: illness or a death in the family. Cases where extensions will not be granted include situations that are typical of student life: having multiple due dates, work commitments etc. Tutorial instructors (TA's) will not be able to provide extension on their own and must receive permission from the course instructor first. (Note: Forgetting to hand your assignment or a component of your assignment in does not constitute a sufficient reason for handing your assignment late).
  3. Method of submission: You are to submit your assignment using D2L [help link]. Make sure that you [check the contents of your submitted files] (e.g., is the file okay or was it corrupted, is it the correct version etc.). It's your responsibility to do this! (Make sure that your submit your assignment with enough time before it comes due for you to do a check).
  4. Identifying information: All assignments should include contact information (full name and student ID number) at the very top of your program in the class where the 'main()' function/method resides.
  5. Collaboration: Assignments must reflect individual work, group work is not allowed in this class nor can you copy the work of others.  For more detailed information as to what constitutes academic misconduct (i.e., cheating) for this course please read the following [link].
  6. Execution: programs must run on the computer science network.  If you write you code in the lab and work remotely using a remote login program such as Putty or SSH. If you choose to install Java on your own computer then it is your responsibility to ensure that your program will run properly here. It's not recommended that you use an IDE for writing your programs but if you use one then make sure that you submit your program in the form of individual text ".java" files (one for each class that you define).
  7. Source code: in order to get any credit for your work you must submit all relevant dot-java files for the assignment (e.g., Driver.java). If you only submit your byte code files (e.g. Driver.class) then you will not be awarded any credit.

D2L configuration for this course