Professional Documents
Culture Documents
Java 2
Java 2
2. 'reatea clas medReetangle with two data members- length and breadth and a method to caleulate the
fca which is
'length"breadth'. The class has three constructors which are:
a. having n0 parameter values of both length and breadth are
-
Now, ereate objects of the 'Rectangle' class having none, one and two parameters and print their arcas.
Class Diagram: P i
-:ink
-b jnt
+avca); in
Program
pacicoge
ubC casS pectangle {
PiMak int A
Pivalk ink b
RUbic in anac)
cum
RbIC Peckcingle C)
b0
iht bi
PybC veclang Cihko
a
PUbIC Peckana CMk o
Publk tangtr Stntg toshing ()
cuy ('ag4 arca ())
OtKo
fub ct o s aa
gah
fectangle CEneu
eckangle (l0, 20l
eCeng d newv
Deckongle (c)
Pecangk e new
Deckargle ()
Cystemot Pont/oCc
Syrne u poht ntdJ
ugtem g pont)n (e):
aa2 00
CMalco
21SC1203 COMPUTATIONAL THINKING FOR OBJECT ORIENTED DESIGN
.Create a ClasS Student with instance variables id, name, marks of 3 and two instance netho s
findiotal ) and findAverage (). Create 2 obiects in main ) and accesssubjects
the methods
Display the details using these oDJeets.
along with total and percentage obtained. (Use hard coded input)
Class Diagram:
Program: fatko P1
Fubiccb shkentf
ublc intd
fuLhC.ink ab
pu bic n
PUiC
Y2atbtC
chum
int
FUbiC teat find ovtogelint o infb, C)
Pz (O-tbt) 3
chuvn
Puc ah vod main(sta rgg agscI)
shudent S ne Student (
aygmau Pah fa (rid: 2wc3\uur )
SJem-a Pahhn(srore= "ohaon")
systmau pan ln (c frdiakal
Shnau Pohtias (sazs,s br o
scb:
hOdonAaaK {sgs,s balo
student s 2OC student c ): Ssia)
agstam a Poht In Ca d 2Cu3| 129)
utema pohH0 ('G nae
'gcran'))
Sygtem-ot Pahth C9. -find
keheal
toqz9,sb=8, s(*a);
sysum-ou htinPshnd
akog(SQ=qSbC
ss S3) ()
akrd
2(CCC3Y ug
chavan
25
O
2(Ooo3 29
21SC1203 - cOMPUTATIONAL THINKING FOR OBJECT ORIENTED DESIGN
Post-lab Task:
1. Create a Class
Engine with attributes enginelD (int). engineType (String). horsepower(int),
engine Cight (float). add constructors, getter, setters and toString () for Engine class. Create 2 objects in
main () and access the
methods using these objects. Dispiay the details
Class Diagram:
Program:
facicog P,
Public closs Engire
Pm ak int Cid ehP
Pnvak trg etur
Pvak doudl ew
PUAiC vid sel cid (in ed)
thisctype cture
PUbh ad actew dau le eu
tis.Cu ew
Pubic in getad )
chu ed
pubic sn gechec)
ctum eh
ruaic g octorg (
u n eme 4cid4n enpne hp eh1 nr
4ey4 in erghe uesh
21SC1203 - cOMPUTATIONAL THINKING FOR OBJECT ORIENTED DESIGN
Pu blic tnnet)
sead lsd)
setehP ehP)
seetyet(etuee
se ew Cau)
:
Publc saic vad maO(Stahg avgst7)
Enane enad Erel
Cc cuGua
-ehP 2000
e-ekyee = hanc
eew SS 2
uSmaut pohtln ( e);
naine e ne ErahrC );
Cehfe loco
f i k y rC? " heyc
e ew y2.2
Sygkn.ak. pahtln(
Qd Put
cnhe ld SY6u
enghe hP 20 co
engine b C honde
ana uwdshh SS
en id
ycu
engno nf
eng ty hevo
en wegh u2-2
21sC1203 cOMPUTATIONALTHINKING FOR OBJECT ORIENTED DESIGN
.Create class
a
Book with
BName, Bld, BAuthor, and YOP (Y ear of
Serter mctnods. B Name must not have anv Publication). Use proper geter and
and spcca special svmbols except '', BId must not have
only a symbols, BAuthor must not have any special any whitespace
4-digit number. Use toString ( to characters and digits, and YOP
should contan
using these objects. formatthethe details of the book. Create 2
access the methods
Display details objects in main ) and
Class Diagram:
Program:
facco Pi
ublic os goo S
Polake
ong Bo, Bd utro
ubic el Fa sual eorne
(Shmgs
ni
c s krgth( ); H+ )
cho CssCho@AtCi)
f(ChorocY ichlehoehc(c)||cladi sPOt
1 C= )
cohhur
ckum use
cu u
ru bNC Vo'd selenane CStnhg s)
f (icvaltd Bome(s))
dotint z 0 , jculergtn);1
chay C2 U.chaxAF Ü)
PCCkovad, ish1pha behic Ce) 11hoval
isparlf
nhoue
falst falsT
cuyd t i
ublk
vodetoutha(Stiy t
i isvali d Roulha t)
Bouhat:
udic vad chyp O (int
si)
if (s> co s9949)
yPS
rudik sh8 eomeC)
chu yP
tockb
bD B1d2czhijn
bqeterae ( y, BOutho Kdi
bhd "465 a"]:
b Gd by. get Byc 20
tide):
prccousto ' s dj"); Bran gona
boutha bj-gel'outhor1: BsdOul
KOukta rsd
P'byyyop(20OuS y,
by gdop