Starting from:

$29.99

Assignment 3 – Part 1 Polymorphism & Pictures

W22 - COMP1006/1406 Part 1 
Assignment 3 – Part 1
Polymorphism & Pictures
Due: Friday, March 4
th at 11:59pm
Submit a single zip file called A3-Part1.zip.
Part 1 of the assignment has 10 marks.
Q1: Polymorphism ________ [5 marks]
Consider the class hierarchy shown to the right.
Each class in the hierarchy will have the following
constructor and overridden toString() method, where
X is replaced with the class name.
public X(){
 super();
 System.out.print(“X”);
}
@Override
public String toString(){
 return “X” + super.toString();
}
Except that in the A class, the constructor is as
above, but the toString() should be
@Override
public String toString(){
 return “A”;
}
A) What is displayed to the screen when the following program is run?
public static void main(String[] args){
 A[] letters = {new B(),new C(),new D(),new E(),new F(),new G()};
 for(A letter: letters){
 if( !(letter instanceof E) ){
 System.out.print(letter);
 }
 }
}
W22 - COMP1006/1406 Part 1 due Friday, March 4
th at 11:59pm
B) Draw a picture of the memory model (stack and heap) at the point in the program above
when the stack has the most activation records in it. You can assume that print() does not call
any other methods from inside it.
Your solution to both parts (A) and (B) should be in a file called A3Part1Q1.pdf. That is, it must
be a pdf file.
You can use something like MS Word or Google docs to write your answer for (A). You can
draw your memory model for part (B) electronically (Word, PowerPoint, Google Docs, or
whatever else you prefer) or draw it by hand (neatly) and take a (good) picture/scan of it and
embed it to your assignment. Add your file to your A4-Part1.zip file.
Q2: Drawing [5 marks]
We have reached the half-way point (more or less) in the semester. Think about your
experience so far in COMP 1006/1406. Think about what you have learned and what you have
done. The joys and frustrations. Think about what you might be able to do with what you have
learned. Your task in this problem is to either draw a picture that expresses this reflection or to
write about it (or a combination of both). My hope in asking you to do this exercise is that you
will critically reflect on what you have learned and perhaps where you would like to take what
you have learned forward. It should also make this assignment a bit lighter than the others. The
intention is that this problem should not cause you any stress. Do not worry about your
“artistic ability”. You will not be graded on how “artistic” your drawing is or how grammatically
correct your writing is. If you put an honest effort into the problem, you will receive full marks.
Have fun!
You can create your drawing or writing in any way you wish but you should save it in PDF
format. Ideally, the size of your drawing should be a standard letter size in horizontal
orientation and the length of writing should not be more than one page. Time permitting, we will
show your pictures to the class.
If you want your submission to remain private (and not shown to the class) then save your file
as private-name.pdf, where name is your name. If you agree to have your picture/text
displayed (possibly this semester or in future semesters of this course or related courses) then
submit your drawing in a file called public-name.pdf, where name is your first (given) name.
Note: For public submissions, do NOT include your full name/ID in your picture/text unless you
are OK with everyone seeing it. Since you are submitting using Brightspace, we already know
who you are so we don’t need this information in your picture.
W22 - COMP1006/1406 Part 1 due Friday, March 4
th at 11:59pm
Note: Offensive/rude/insensitive submissions will receive zero marks and may be forwarded to
the Dean's office depending on the severity. (This has never happened before, and I do not
anticipate it happening now.)
Save your program in a file as specified above and add it to your submission zip file.
Recap [A3-Part1.zip]
Submit a single zip file called A3-Part1.zip. Your zip file should have two (or three) files in it.
● A3Part1Q1.pdf
● Either private-name.pdf or public-name.pdf (or both).
Note: as with the previous assignments, there is a 48-hour grace period. You can submit up
until Sunday, March 6th at 11:59pm without penalty. Remember that there are no guarantees of
any help over the weekend though, so it is really encouraged that you try to submit without
using the grace period.
Note: Part 2 will be posted soon. It will involve implementing the Comparable interface, Abstract
classes, Enum classes and inheritance/polymorphism. 

More products