Gosling and David Holmes, 4th Edition / 3rd Edition
Gosling and David Holmes, 4th Edition / 3rd Edition
Department of CS&IS
CS/IS F213 !"e#t riente$ Pro%rammin%
CS/IS C313 !"e#t riente$ Pro%rammin% an$ Desi%n
Lab-3 Dt.20.08.2014
T&e pre'la! (or) for t&e la! is as follo(s*
1* +ea$ Ch13, 15, 19 from The Java Programming Language, Ken Arnold, James
Gosling and David olmes, 4th !dition " #rd !dition*
2* +ea$ t&e re%ular e,pressions summar- uploa$e$ onto t&e #ourse site*
T&e in'la! (or) for first la! is as follo(s*
Question-1
Part-A
.ou are an eminent P&-si#ist (&o is on t&e /er%e of pro/in% t&e e,isten#e of
(orm&oles* T&e onl- !ottlene#) in t&e pro#ess is t&at -ou &a/e to a$$ /er- /er- !i%
num!ers*
T&ese num!ers e,#ee$ t&e tra$itional limits of lon% or $ou!le*
.ou )no( t&at all t&e &u%e num!ers are $efinitel- non'ne%ati/e 0 123 4*
To sol/e t&is pro!lem -ou #onsult -our #olle%e professor an$ &e su%%est -ou to store
t&e num!ers as strin%s an$ t&en a$$ t&em*
.ou are re5uire$ to #reate an o!"e#t 6u%eInt (&i#& stores t&e &u%e num!er as strin%
an$ allo(s its a$$ition to anot&er 6u%eInt*
T&e first line of input #ontains 7121 follo(e$ !- 7 lines* 8a#& line #ontains t(o strin%
representations of num!ers separate$ !- spa#e* .ou nee$ to output t&e sum of t&e
t(o num!ers in ea#& line*
$A%PL! &'P(T)
3
1239 :;<9=
3 <9>;
=<:<;:<>9 139==
$A%PL! *(TP(T)
;31;<
<9>;
=<;33193<
Part-B
6a/in% $one t&is, no( a$$ t&e fun#tionalit- to #ompare t(o 6u%eInt* T&e result of
#omparison #an !e one of t&e follo(in%?
num1*#ompare0num24 '1 '1 if num1@num2
num1*#ompare0num24 '1 1 if num2@num1
num1*#ompare0num24 '1 3 if num12num2
Question-2
Define a #lass Agency (it& t&e follo(in% parameters?
A%en#- 7ame, A%en#- A$$ress, A%en#- P&one 7um!er, A%en#- TI7 7um!er0Ta,'
Pa-er I$entifi#ation 7um!er4 an$ A%en#- PA7 7um!er0Personal A##ount 7um!er4
T&e parameters are restri#te$ to &a/e onl- #ertain possi!le /alues?
A%en#- 7ame? Strin%
A%en#- A$$ress? Strin%
P&one 7um!er? Format of t&e p&one num!er is ? @Countr- Co$e1@STD
Co$e1@P&one 7um!er1
Countr- #o$e &as to !e%in (it& BCD follo(e$ !- 2 $i%its*
8%? C<1 STD Co$e? = Di%its P&one 7um!er? ; $i%its
TI7 7um!er? Format of TI7 num!er is? @2 letters a'E A'F1@spa#e1@: $i%its1
PA7 7um!er? Format of PA7 num!er is ? @= letters a'E A'F1@9 $i%its1@2 letters a'E A'
F1
Define t(o #onstru#tors for t&is #lass? one t&at a##epts 7ame an$ A$$ress as t&e
parameters an$ assi%ns ot&er parameters to an- #onstant non'null /alue an$ t&e ot&er
t&at a##epts all t&e parameters*
Define t&e follo(in% met&o$s?
a) A met&o$ t&at a##epts name an$ a$$ress as t&e parameters from t&e )e-!oar$ an$
#&e#)s (&et&er an a%en#- of t&at o!"e#t e,ists or not* If -es t&en print True, else
#reate an a%en#- o!"e#t (it& t&at parameters*
!4 A met&o$ t&at a##epts a num!er (it& 9 $i%its an$ #&e#)s (&et&er an a%en#- (it&
PA7 num!er &a/in% t&at 9 $i%it e,ists or not*
Create "a/a$o# for t&is pro%ram*
T&e post'la! (or) for first la! is %i/en !elo(* 0to !e #&e#) in ne,t la!4
Question-3
T&ere &as !een an alien in/asion from t&e resi$ents of Planet A/a"* T&e- &a/e plante$
multiple Antimatter !om!s an$ t&e- (ill all $etonate unless an- one of t&em is $efuse$
usin% a pass(or$*
.ou as a super a(esome &a#)er &a/e !een a!le to e,tra#t some &ints a!out t&e
pass(or$ an$ a &u%e list of pass(or$s* Due to some stran%e #oin#i$en#e, -ou see t&at
t&e alien lan%ua%es #ontain all t&e stan$ar$ ASCII #&ara#ters* .ou &a/e to s&ortlist t&e
pro!a!le pass(or$s !ase$ on t&e follo(in% rules an$ #&e#) if it fits*
.ou are nee$ to implement t&e main an$ an- ot&er met&o$ !o$- -ou #onsi$er
ne#essar- in t&e pro/i$e$ AlienInvasion!ava file* T&e final #ompute$ pass(or$ must !e
passe$ to $efuse0Strin%4 met&o$ to #&e#) t&e result*
PASSG+D +HI8S?
1* T&e pass(or$ must !e at least 23 #&ara#ter lon%
2* t&e pass(or$ must #ontain a $i%it 0 3'< 4
3* t&e $i%it must !e pre#e$e$ !- some non'numeri# #&ara#ter
=* t&e en$ of t&e pass(or$ must !e a $ate of format
DD/JJ/.... 66?JJ
-es t&ere is a spa#e in !et(een an$ all t&e $i%its must !e present* Di%its o##urrin%
in t&is part of t&e pass(or$ are not #onsi$ere$ as satisfia!ilit- #on$ition of rule 2*
9* If t&ere is a K si%n !efore t&e first numeri# $i%it o##urs, t&e pass(or$ is in/ali$
.ou nee$ to re$ire#t t&e pro/i$e$ input file into t&e pro%ram an$ t&en #&e#) if -ou #an
sa/e t&e (orl$*
T&e pass(or$s are %i/en in t&e file "ass#or$t%t*
&e'erences(
Immuta!le ar!itrar- pre#ision inte%er #lass is a/aila!le in La/a as Bi%Inte%er
&ttp?//$o#s*ora#le*#om/"a/ase/:/$o#s/api/"a/a/mat&/Bi%Inte%er*&tml
+ea$in% input into a La/a pro%ram t&rou%& )canner #lass
&ttp?//$o#s*ora#le*#om/"a/ase/:/$o#s/api/"a/a/util/S#anner*&tml
&ttp?//sta#)o/erflo(*#om/5uestions/11;:1923/&o('#oul$'i'rea$'input'from't&e'#onsole'
usin%'t&e's#anner'#lass
La/a +e%ular 8,pressions Pa#)a%e
&ttp?//$o#s*ora#le*#om/"a/ase/:/$o#s/api/"a/a/util/re%e,/pa#)a%e'summar-*&tml
Summar- of +e%ular 8,pressions Patterns
&ttp?//$o#s*ora#le*#om/"a/ase/:/$o#s/api/"a/a/util/re%e,/Pattern*&tml
A tutorial on +e%8,
&ttp?//(((*/o%ella*#om/tutorials/La/a+e%ular8,pressions/arti#le*&tml