Practical Software Development Using Uml and Java School of
Practical Software Development Using Uml and Java School of
Software Engineering:
Practical Software Development
Using UML and Java
Solution Manual - CHAPTER 2
By: Paul Holden
Exercise 2.1: Which of the following items do you think should be a class, and which should be
an instance? For any item which should be an instance, name a suitable class for it. If you think
an item could be a class or an instance, depending on circumstances, explain why.
Common Mistake: Saying that this should be a class with instances’car’, ‘truck’, ‘van’.
This would be correct if the name of the class was General Motor Vehicle.
c) Student: This could be a class. Instances would be ‘John Smith’ and ‘The student with student
number 1234567’
d) Computer Science Student: This is a class and it would have instances such as ‘John Smith’
and ‘The computer Science Student with student number 1234567’
Common Mistake: Saying that this is an instance. For this to be an instance, the name should
be just ‘Computer Science’ and a suitable class would be Student.
e) Mary Smith: This is an instance and a suitable class for it would be Employee or Person.
f) Game: This would be a class and a suitable instance would be ‘The game of Chess’
g) Board Game: This is a class. A suitable instance would be ‘The board game Snakes and
Ladders’
Common Mistake: To say that this is a class. To be a class, it would be preferable to name
the class ChessGame.
i) The game of Chess between Tom and Jane which started at 2:30 p.m. yesterday: This would be
an instance and a suitable class would be ChessGame.
j) Car: This would be a class and instances would be ‘John’s Porsche’ and ‘The Ferrari with
License Number ABC 123’
k) Mazda Car: This would be a class and a suitable instance would be ‘The Mazda Car with VIN
number 12345’
Common Mistake: Mazda Car should not be considered an instance. It could be however
an instance if the name was changed to Mazda.
l) The car with serial number JM198765T4: This is an instance and a suitable class would be
Car
.
Exercise 2.3: The following words in English have different meanings. In some cases, one might
want to create several different classes to represent each of the different meanings. Name and
describe as many classes as you could think of that might be derived from these words.
a) Video: VideoRecording: this class would describe a video recording and could have such
instances as ‘The video (recording) made on Jan 1, 2000’. VideoShowing: this class would
describe the showing of a video and an instance would be ‘The video that will be shown Jan 1
2003’. Note that there can be many showings of a VideoRecording.
b) Flight: RegularFlight: This would describe a flight which has a regular schedule and an
instance would be ‘The flight that leaves from Ottawa to Toronto everyday at 8 a.m.’.
CharteredFlight: This would describe a chartered flight and an instance would be ‘The
chartered flight which left 01/01/99 from Toronto to Anchorage’. SpecificFlight. This would
describe a particular occurrence of a RegularFlight.
c) Program: TelevisionProgram: this class would describe a television program and instances
could ‘Frasier’ or ‘Law and Order’. EpisodeOfProgram: This class could describe an episode of
a television program that played and an instance would be ‘The final episode of Seinfeld’.
ShowingOfEpisode: An example instance of this might be: The rerun of the final episode of
Seinfeld that was played on Dec 20, 2000.
d) Book: BookTitle: This would describe a certain title and an instance would be ‘The fiction
book Catcher in the Rye’ CopyOfBook: This would describe a copy of a book and an instance
would be ‘The copy of Catcher of the Rye with library reference number 123456’.
Exercise 2.4: Identify the attributes that might be present in the following classes. Try to be
reasonably exhaustive.
Common Mistake: Not using proper naming for classes and attributes. Classes begin with a
capital and attributes begin with a non-capital. Also, Each new word in the name uses a
capital.
Exercise 2.7: Identify the operations that might be present in the following sets of classes;
highlight the polymorphic operations (operations that would be done differently in different
classes).
Exercise 2.8: Which of the following superclass-subclass pairs are clearly invalid, and why?
Note: This question was a bit confusing, since it implies that all of the following are classes,
when some appear to be instances. We apologise for the confusion!
f) People - Customer: This should be invalid because ‘People’ ought to be called ‘Person’, but
the question led you to believe that ‘People’ is a valid class, hence this was accepted as valid.
c)
Bus: busNumber, numberOfPassengers
CharteredBus:
charteringOrganization LuxuryBus:
levelOfLuxury.
TourBus: sightViewed, tourGuideNamed
ExpressBus: frequency
Note that in the above, it would have been even better to have split up the hierarchy into one
hierarchy of types of vehicle: LuxuryBus, and another hierarchy of types of Route:
CharteredBus, TourBus, ExpressBus.
Route: routeNumber.
BusRoute: typeOfBus.
d)
MediaPlayer: inputFormat
Television: hasRemoteControl, diagonalViewableArea
VCR: tapeFormat, .numberOfHeads
TapeDeck: hasEditingFacilities
MediaStorageDevice: capacity.
CD: numberOfTracks.
Cassette: length
e)Currency: valueInUSDollars.
CanadianDollars: Should really be an instance
USDollars: Should really be an instance
FinancialInstitution: name
Bank:
CreditUnion.
BankBranch: employees.
FinancialInstrument: referenceNumber.
BankAccount: maxWithdrawal.
Cheque: serviceCharge.
CreditCard: limit
VISACard
MasterCardCard:
DebitCard: dailyLimit
BankMachine: maxStoredCurrency.
Loan: loanAmount.
ExchangeRate: rateToTheUSDollar
f)
HotelRoom: roomNumber, rate
Suite
ConferenceRoom: numberOfSeats.
MeetingRoom: numberOfSeats.
Ballroom: roomCapacity.
Hilton: address.. Should really be an Instance or called HiltonHotel (which has specific
instances)
Reservation: startDate, endDate
Booking: roomBooked, client
Exercise 2.10: This question requires knowledge of very basic geometry. Describe in one line
how different polymorphic implementations of the following operations from Figure 2.8 would
work in classes Rectangle, RegularPolygon, Circle and their superclasses.
c)
area in Rectangle: The area operation defined in Rectangle would override the one in
TwoDShape.
area in RegularPolygon: The area operation defined in RegularPolygon would override the
one in TwoDShape.
area in Circle: The area operation defined in Circle would override the one in TwoDShape.
d)
center in Rectangle: The center operation in the superclass SimplePolygon would be used. This
overrides the center in TwoDShape.
center in RegularPolygon: The center operation in the superclass SimplePolygon would be
used. This overrides the center in TwoDShape.
center in Circle: The center operation defined in Circle would override the one in TwoDShape.
Exercise 2.12: In which of the following situations would dynamic binding be needed:
c) Variable of type Polygon invokes boundingRectangle: Yes, dynamic binding would be needed
because Rectangle overrides boundingRectange.
d) Variable of type Ellipsoid invokes scale: No, dynamic binding would not be needed because
none of its subclasses overrides scale.
e) Variable of type RegularPolygon invokes translate: No, because RegularPolygon is a leaf
class therefore it is known at runtime which translate it will use.
f) Variable of type TwoDShape invokes boundingRectangle: Yes, dynamic binding will be
needed because many subclasses override boundingRectangle.