Week2 Sample -2
Page 3 of 16
Given the UML for the Superman (the one with the inheritance), let's think about what sort of code you
can/may derive from it.
This UML tells us that "Superhero" is a super class, and Superman is a subclass so we could do
Week 3 Sample -2
Page 6 of 16
Given the UML for the icecream cone, let's think about what code can be derived.
Starting with cone, Cone will have at least/most one scoop above it.
class Cone cfw_
Since Scoop will have flavor as an attribute and
1. Get the all the facts about ice-cream
You can first list out everything you can think of about ice-cream
ice cream comes on a cone
there are different kinds
multiple scoops can be stacked up.
Page 10 of 16
Here are sample answers:
public classBookShelfimplements Aggregate cfw_
this.books = newArrayList<Book>(initialsize);
Page 12 of 16
java.io.InputStreamclass uses "TemplateMethod" design pattern. Check JDK API reference to see
which methods are required to be implemented in a subclass ofjava.io.InputStreamclass.
All subclass ofImputStreamis
Step 1 (facts finding/brain storming)
You can list anything you can think of to model the piecewise function:
There are ranges of independent variable (x of y=f(x).
slope of the linear function stays the same within each range.
within each range
Week 10 Sample
Page 14 of 16
In the lecture, Memento class
In order to model "Superman", we will go through the basic three
1. Understand all the facts
* Superman is one of superhero.
* Superheros fight against evil.
* Hence, Superman fights against evil.