Upload
nemac-nemkic
View
218
Download
0
Embed Size (px)
Citation preview
7/23/2019 03. OOP Inheritance and Abstraction Homework
http://slidepdf.com/reader/full/03-oop-inheritance-and-abstraction-homework 1/2Follow Page 1 of 2
© Software University Foundation (softuni.org). This work is liensed under the!!"#$"%!"S& liense.
Homework: Inheritance and Abstraction This dou'ent denes the ho'ework assign'ents fro' the **P !ourse + Software
University. Please su,'it as ho'ework a single zip - rar - 7z arhive holding the solutions
(soure ode) of all ,elow desri,ed ro,le's. The solutions should ,e written in !/.
Problem 1. Human, Studentand Worker
0ene an abstract lass Human holding a rst name and a last name.
• 0ene a lass Student derived fro' Human that has a eld !acult" number ("1
digits - letters).
• 0ene a lass Worker derived fro' Human with elds WeekSalar" and
WorkHoursPer#a" and 'ethod $one"PerHour%& that returns the ay'ent earned
,y hour ,y the worker.
• 0ene the roer onstrutors and roerties for the lasses in your lass hierarhy.
•
3nitiali4e a list of 1 students and sort the' ,y faulty nu',er in asending order (usea 53%6 7uery or the 'rder("%& e8tension 'ethod). 3nitiali4e a list of 1 workers and
sort the' ,y ay'ent er hour in desending order.
• 9erge the lists and then sort the' ,y rst na'e and last na'e.
Problem ). Animals!reate an abstract lass Animal holding na'e age and gender.
• !reate a hierarhy with lasses #o* +ro* at -itten and omcat. 0ogs frogs and
ats are ani'als. ;ittens are fe'ale ats and To'ats are 'ale ats. 0ene useful
onstrutors and 'ethods.
• 0ene an interfae ISoundProducible whih holds the 'ethod ProduceSound%&. &ll
ani'als should i'le'ent this interfae. The ProduceSound%& 'ethod should
rodue a sei sound deending on the ani'al invoking it (e.g. the dog should
,ark).
• !reate an array of di<erent kinds of ani'als and alulate the average age of eah
kind of ani'al using 53%6.
Problem /. ompan"
Hierarch"!reate the following **P lass hierarhy:
• Person = general lass for anyone holding id rst name and last name.o 0mplo"ee = general lass for all e'loyees holding the eld salar" and
department. The deart'ent an only ,e one of the following: Production
Accountin* Sales or $arketin*. $ana*er = holds a set of emplo"ees under his o''and.
e*ular0mplo"ee
- Sales0mplo"ee = holds a set of sales. & sale holds product
name date and price.- #e2eloper = holds a set of pro3ects. & ro>et holds pro3ect
name pro3ect start date details and a state (open or closed ).& ro>et an ,e losed through the 'ethod losePro3ect%&.
7/23/2019 03. OOP Inheritance and Abstraction Homework
http://slidepdf.com/reader/full/03-oop-inheritance-and-abstraction-homework 2/2Follow Page 2 of 2
© Software University Foundation (softuni.org). This work is liensed under the!!"#$"%!"S& liense.
o ustomer = holds the net purchase amount (total a'ount of 'oney the
usto'er has sent).
?8trat inter!aces for eah lass. (e.g. IPerson I0mplo"ee I$ana*er et.) The interfaes
should hold their u,li roerties and 'ethods (e.g. IPerson should hold id rst name and
last name). ?ah lass should i'le'ent its resetive interfae.
0ene roer onstrutors. &void ode duliation through a,stration. ?nasulate all data
and validate the inut. Throw e8etions where neessary. *verride oStrin*%& in all lasses
to rint detailed infor'ation a,out the o,>et.
!reate several e'loyees of tye 9anager Sales?'loyee and 0eveloer and add the' in a
sin*le olletion. Finally rint the' in a for"eah loo.