Ctod Week 6
Ctod Week 6
Lab Session:
3. What is
method signature? What are the
Method ciarature consicist methodthings it consists of?
Paramete list indicates te name and paranetey li
panameteve. ronametes hd det o
4. What is
method
Tot ox rnore overloading?
metbocts hNin
aiteven metho ciqna 6ame name ht ath
5. What is
turetithin the come class.
method overriding?
to povid a teatwe Jiva fhat alloo a sabcag
in
alrendy prcvided bynmpeme nfaia fon a metiod that is
ie super clas
In-lab:
1. Write the following code in your editor below:
A class named Arithmetic with a method named add that
as parameters and takes integeIo
returns an integer denoting their
A class named Adder that
LINK: bit.ly/CTOOD-W6P02
inherits from asuDer classsum.
named Arithmeu
Class Diagram: kla tockage
lass Name Aithmetic Ader
Solrtín >cias
clacs Solation f
pu~ie statie oid main (shing t) ag
feolie
Aldev a-neo Adder()',
+runey:void
Program:
pablie cay Bikef
publie void Yun() coheeis "):
ten("A bike has too
Septem out pin
wheels
ikes ha ve tvep
Post lab:
+detrem(s:Ghing
Metinod,
jtdetine-we):gi
Program:
.mpert joa util
alas Picyeiei
hing defne-merg
Yetuan a vhicle toith (edas"
elas Motolycle exterdi bcydef
shing defhe -meOf
retn o
ycle with an eqme";
>Attibetes
4addldoudrsehe
4nd(shing) stng Molhodc
todd (int():in
Program:
klaj
package
pudie dous toeek&
pubtic atetie docaale add (douse a, doabe bs
vetorn athy
3putslie okate stinq add
Qdd (sting'
(ting t, hin oX
rethoin St
3 publie ctate int acdd Cint( ) f
Georehiear Cetin'e
boie Color. iergth dou ble
toci
Pecargte etests;
Rec tagr
194
3. Create a class Area with three static overloading methods calculateArea
(double radius) to find area of a cicle,calculateArea (double 1,double b) to find
area of a rectangle and calculateArea(int s) to find area of a square. Access them
from the main) of same class. (Use Command Line Arguments)
Class Diagram: klu tckag
Area ClasG Name
Atioutes
+caltea Cdouble). doude
+al Aee (Aoute,doubley : doube Metigde.
4 calea Cint: int
main (arStingr):vo id
klu )
Program:
packag
prublie cass tren
pubtic satic deeble cal Are(double Raciuss
te tuon Mceth PI Meth
PooRodies,2)';
Spuiotie stahie doute al treu (daubielegit deusle coide) £
reten legtht conth
3 pebic state nt caltrea ((int f
Yetem ts
puslic datic vod mainlhingarsk
if Ceg levgih-:01
Systemutpiantho (noCommand fine thrmnli;
Tetuom
int S
Siplemcut pint fn("ca ¢ Square is'+ ol Ara(),
ele it (o length
dede Radies eCoube pae Double (asLo))
s:cdArea
Syle out pintlm 'Ae of+ drcle
deuble lergth =Doubse petoue(arost (eadiu)
double aidth Dauble poseDoube (agA cn
Sytmtat-pint tofAyea tReckange ts:+ cadlhea (lenyth, tdrh )
3glem out inn("No cominard lire Aqument"'y
Ctpet
inpt3
108
4. Create GeometricShape Class with attributes borderColor (String), filled
(Boolean type). This is inherited by Rectangle Class with length and width as
attributes.The Rectangle class is further inherited by Cuboid class with height
field as its instance variable. Add mutators, accessors and toString () methods.
Use super keyword. (Multilevel Inheritance). Enhance all classes with no
parameterized and parameterized constructor and Chain the constructors using
super keyword.
Class Diagram:
+sti'ecooat
Program: klus
puble cs, Geometnc Shapei thisbe Bondes Colo
Program:
fnckaqe hle;
priuateving rvre)
I.
tname(o
reton
puite chk Mtxster2 ( ing nane%
atacho
rekon KiH Monster 2"1petName(+' is atetina;
puble dau childMter 3 etends Mosterj
puble child Noesler3 (Sing t mey
Supertame;
pudic Shiì nq atak (){
vetum child Hyester s is'tqetNane)+ "'atacks
pablic dauy MbasterDeof
pulslic staie void nan(sting) ara
M es ter m ne
it Cop< pie)i
Tetun opi
Tnput:
tce:lt, s,3.6,4)
(For
Evaluator's use only)
Comment of the Evaluator (if Any)
Evaluator's Observation
4 2outof
Marks Secured: