Você está na página 1de 5

SEMESTER - III CS 3102 JAVA PROGRAMMING LAB ASSIGNMENTS DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, B. I. T.

MESRA CS & IT Day-1, 2, and 3: Use of Constants, Variables, and Data types; Use of Operators and Expressions; Decision Ma in! and branc"in!; Decision Ma in! and #oopin!; $trin!s; %rrays& Note: The questions marked * are for home work. You are expected to solve 4 questions in each regular laborator session and solutions for ! home work problems to be shown in the next class. "ailing which# the sessional marks for that class will not be considered. $heating in an form is strictl intolerable. '-1 ("e para)eter *ee day is tr+e if it is a *ee day, and t"e para)eter ,acation is tr+e if *e are on ,acation& -e sleep in if it is not a *ee day or *e.re on ,acation& /et+rn tr+e if *e sleep in& '-2 0i,en t*o int ,al+es, ret+rn t"eir s+)& Unless t"e t*o ,al+es are t"e sa)e, t"en ret+rn do+ble t"eir s+)& '-3 0i,en an int n, ret+rn t"e absol+te difference bet*een n and 21, except ret+rn do+ble t"e absol+te difference if n is o,er 21& 1'-2 0i,en 2 ints, a and b, ret+rn tr+e if one if t"e) is 13 or if t"eir s+) is 13& 1'-4 0i,en 2 int ,al+es, ret+rn tr+e if one is ne!ati,e and one is positi,e& Unless nega !"e is tr+e, t"en t"ey bot" )+st be ne!ati,e& '-5 0i,en a strin!, ret+rn a ne* strin! *"ere t"e first and last c"ars "a,e been exc"an!ed& front6ac 78code89 : 8eodc8 front6ac 78a89 : 8a8 front6ac 78ab89 : 8ba8 '-; 0i,en a strin!, ta e t"e last c"ar and ret+rn a ne* strin! *it" t"e last c"ar added at t"e front and bac , so 8cat8 yields 8tcatt8& ("e ori!inal strin! *ill be len!t" 1 or )ore& bac %ro+nd78cat89 : 8tcatt8 bac %ro+nd78<ello89 : 8o<elloo8 bac %ro+nd78a89 : 8aaa8 1'-= 0i,en a strin!, ret+rn tr+e if t"e strin! starts *it" 8"i8 and false ot"er*ise& '-> 0i,en t"ree int ,al+es, % 6 C, ret+rn t"e lar!est& '-13 0i,en 2 positi,e int ,al+es, ret+rn t"e lar!er ,al+e t"at is in t"e ran!e 13&&23 incl+si,e, or ret+rn 3 if neit"er is in t"at ran!e& 1'-11 0i,en a strin!, ret+rn a ne* strin! *"ere t"e last 3 c"ars are no* in +pper case& ?f t"e strin! "as less t"an 3 c"ars, +ppercase *"ate,er is t"ere& @ote t"at str&toUpperCase79 ret+rns t"e +ppercase ,ersion of a strin!& '-12 0i,en n of 1 or )ore, ret+rn t"e factorial of n, *"ic" is n 1 7n-19 1 7n-29 &&& 1& Co)p+te t"e res+lt rec+rsi,ely 7*it"o+t loops9& '-13 ("e fibonacci seA+ence is a fa)o+s bit of )at"e)atics, and it "appens to "a,e a rec+rsi,e definition& ("e first t*o ,al+es in t"e seA+ence are 3 and 1 7essentially 2 base cases9& Eac" s+bseA+ent ,al+e is t"e s+) of t"e pre,io+s t*o ,al+es, so t"e *"ole seA+ence is: 3, 1, 1, 2, 3, 4, =, 13, 21 and so on& Define a rec+rsi,e fibonacci7n9 )et"od t"at ret+rns t"e nt" fibonacci n+)ber, *it" nB3 representin! t"e start of t"e seA+ence&

'-12 0i,en a non-ne!ati,e int n, ret+rn t"e s+) of its di!its rec+rsi,ely 7no loops9& @ote t"at )od 7C9 by 13 yields t"e ri!"t)ost di!it 7125 C 13 is 59, *"ile di,ide 7D9 by 13 re)o,es t"e ri!"t)ost di!it 7125 D 13 is 129& 1'-14 0i,en a non-ne!ati,e int n, ret+rn t"e co+nt of t"e occ+rrences of ; as a di!it, so for exa)ple ;1; yields 2& 7no loops9& @ote t"at )od 7C9 by 13 yields t"e ri!"t)ost di!it 7125 C 13 is 59, *"ile di,ide 7D9 by 13 re)o,es t"e ri!"t)ost di!it 7125 D 13 is 129& '-15 -rite a pro!ra) to find t"e n+)ber of and s+) of all inte!ers !reater t"an 233 t"at are di,isible by ;& 1'-1; 0i,en any n+)ber, *rite a pro!ra) +sin! while loop to re,erse t"e di!its of t"e n+)ber& '-1= -rite a pro!ra) to deter)ine t"e s+) of t"e follo*in! "ar)onic series for a !i,en ,al+e of n: 1E1D2E1D3E ----- E1Dn ("e ,al+e of n s"o+ld be !i,en interacti,ely t"ro+!" t"e eyboard& 1'-1> -rite a pro!ra) t"at co)p+tes t"e area of a trian!le& ("e sides of trian!le s"o+ld be !i,en interacti,ely t"ro+!" t"e eyboard& 1'-23 -rite a pro!ra) to sort any list of !i,en n+)bers& 1'-21 -rite a pro!ra) to add t*o 3 by 3 )atrices& Day 2, 4, 5: ?n"eritance pro!ra))in! tec"niA+es '-22 -rite a Fa,a code to find t"e distance fro) /anc"i to )aFor cities of ?ndia& <int: Create an $trin! array of )aFor cities and inte!er array of distances& User !i,es t"e city na)e and t"e sa)e is searc"ed 7+se binary searc"9 in t"e respecti,e array and displays res+lt& '-23 -rite a %atient class *"ic" in"erits fro) t"e %erson class& Go+ )ay also need to +se t"e &one class& ("e %atient class reA+ires t"e follo*in!: a ,ariable to store t"e patient n+)ber for t"e patient a ,ariable to store t"e "ospital a ,ariable to store t"e patient .s year of Foinin! t"e "ospital a ,ariable to store t"e patient .s address a ,ariable to store t"e )edical fees t"at t"e patient pays constr+ctor )et"ods, *"ic" initialise t"e ,ariables )et"ods to set t"e "ospital , year of Foinin! and address )et"ods to !et t"e "ospital, year of Foinin! and address a )et"od to calc+late t"e )edical fees : ?t s"o+ld ta e a &one obFect 7t"e basic fee per year9 as a para)eter and +se it to ret+rn t"e basic fee for t"e patient& % patient s"o+ld pay t"e basic fee for t"e year of / 1233, 43& a to$trin! )et"od '-22: a& Explain t"e difference bet*een early and lateDdyna)ic bindin!& b& -"ic" ey*ord can be +sed to indicate t"at a )et"od cannot be o,erridden *it" a ne* definition in a deri,ed classH c& 0i,e t"e code for an abstract )et"od called !et%rea79 t"at calc+lates and ret+rns t"e area of a s"ape as a do+ble& '-24: % s)all co)pany dealin! *it" transportation "as F+st p+rc"ased a co)p+ter for its ne* a+to)ated reser,ations syste)& Go+ "a,e been as ed to pro!ra) t"e ne* syste)& Go+ are to *rite a pro!ra) called 'eservation( stem to assi!n seats on a ,e"icle& Go+r class also reA+ires t"e follo*in!: Ia constr+ctor )et"od, *"ic" initialise t"e ,ariables a )et"od to assi!n t"e capacity of seatin!&

a )et"od for assi!nin! seats& Use a 1-d array to represent t"e seatin! c"art of t"e plane& ?nitialiJe all t"e ele)ents of t"e array to 3 to indicate t"at all t"e seats are e)pty& %s eac" seat is assi!ned, set t"e correspondin! ele)ents of t"e array to 1 to indicate t"at t"e seat is no lon!er a,ailable& Go+r pro!ra) s"o+ld, of co+rse ne,er assi!n a seat t"at "as already been assi!ned& appropriate )+tator and accessor )et"ods ("e co)pany also needs a pro!ra) dealin! especially *it" its only plane *it" eac" fli!"t "a,in! a capacity of 13 seats& @a)e t"is class )irline'eservation( stem. ("is class is a type of 'eservation( stem b+t t"e *ay it reser,es seats are different& Go+r pro!ra) s"o+ld display t"e follo*in! )en+ of alternati,es for reser,in! a seat on t"e fli!"t: P#ea$e %&e 1 '() *$+(,!ngP#ea$e %&e 2 '() *n(n-$+(,!ng?f t"e person types 1,t"en yo+r pro!ra) s"o+ld assi!n a seat in t"e s)o in! section7seats 1-49 ?f t"e person types 2,t"en yo+r pro!ra) s"o+ld assi!n a seat in t"e non-s)o in! section7seats 5-139& Go+r pro!ra) s"o+ld t"en print a boardin! pass indicatin! t"e personKs seat n+)ber and *"et"er it is in t"e s)o in! or non-s)o in! section of t"e plane& -"en t"e s)o in! section is f+ll, yo+r pro!ra) s"o+ld as t"e person if it is acceptable to be placed in t"e non-s)o in! section 7and ,ice ,ersa9& ?f yes, t"en )a e t"e appropriate seat assi!n)ent& ?f no, t"en print t"e )essa!e L Ne. '#!g/ #ea"e$ !n 3 /(0)$. M Create a )ain79 )et"od to test t"e next sc"ed+led fli!"t& '-25: Create a s+perclass, $t+dent, and t*o s+bclasses, Under!rad and 0rad& ("e s+perclass $t+dent s"o+ld "a,e t"e follo*in! data )e)bers: na)e, ?D, !rade, a!e, and address& ("e s+perclass, $t+dent s"o+ld "a,e at least one )et"od: boolean isNassed 7do+ble !rade9 ("e p+rpose of t"e isNassed )et"od is to ta e one para)eter, !rade 7,al+e bet*een 3 and 1339 and c"ec *"et"er t"e !rade "as passed t"e reA+ire)ent for passin! a co+rse& ?n t"e $t+dent class t"is )et"od s"o+ld be e)pty as an abstract )et"od& ("e t*o s+bclasses, 0rad and Under!rad, *ill in"erit all data )e)bers of t"e $t+dent class and o,erride t"e )et"od isNassed& Oor t"e Under0rad class, if t"e !rade is abo,e ;3&3, t"en isNassed ret+rns tr+e, ot"er*ise it ret+rns false& Oor t"e 0rad class, if t"e !rade is abo,e =3&3, t"en isNassed ret+rns tr+e, ot"er*ise ret+rns false& Create a test class for yo+r t"ree classes& ?n t"e test class, create one 0rad obFect and one Under!rad obFect& Oor eac" obFect, pro,ide a !rade and display t"e res+lts of t"e isNassed )et"od& '-2;: a& <o* do yo+ +se t"e scope of class )e)bers and )et"ods to "ide infor)ation fro) ot"er classesH b& -"en s"o+ld yo+ +se in"eritance pro!ra))in! tec"niA+es to sol,e proble)sH c& -"at are t"e benefits of +sin! in"eritanceH (o sa,e ti)eH $"orter pro!ra)sH d& Pa,a can deal *it" sin!le in"eritance 7one s+perclass *it" )+ltiple s+bclasses9& <o* can a class in"erit fro) )ore t"an one s+perclass 7)+ltiple in"eritances9H '-2=: Create an applet pro!ra) for 6anner; banner text 7Go+r /oll @o&9 s"o+ld be passed as para)eter& ("is applet creates a t"read t"at scrolls t"e )essa!e contained in )essa!e ri!"t to left across t"e applet.s *indo* Q also +ses stat+s *indo*&

'-2>: Create an applet pro!ra) for Men+ de)onstration& Men+ bar s"o+ld contain Oile, Edit, Vie* and its s+b)en+s& '-33: Create #abels 7One, (*o Q ("ree9, add 6+ttons 7Ges, @o, Undecided9 *"en +ser clic any b+tton s"o* )essa!e re!ardin! +ser clic , add C"ec boxes7-indo*s >=DRN, -indo*s @(D23339 *"en +ser c"ose any c"ec box s"o* )essa!e re!ardin! +ser c"oice Q add text boxes 7na)e, pass*ord9 and text on t"ese textboxes s"o+ld be displayed on Nanel& '-31: Dra* colo+r lines, /ectan!le, Oilled /ectan!le, /o+nded /ectan!le, Oilled /o+nded /ectan!le, O,al, Oilled o,al, arc, fill arc, Q poly!on e,ery dra*in! s"ape s"o+ld be in different colo+r, -rite a text L"ello e,eryoneM at t"e center& '-32: Create an applet pro!ra) for ey e,ents it s"o+ld reco!niJe nor)al as *ell as special eys Q s"o+ld be displayed on t"e panel& '-33: Create an applet pro!ra) for )o+se e,ents it s"o+ld reco!niJe )o+se entry, exit, and its coordinates& (ip: -"en a *eb pa!e is to be de,eloped, t"e follo*in! are to be planned: 1& Content of t"e pa!e 2& %ppearance of t"e pa!e %ppearance of t"e pa!e is coded in <(M# +sin! <(M# ta!s& '-32: Desi!n a <(M# pa!e 7*eb pa!e9 describin! yo+r profile in one para!rap"& Desi!n in s+c" a *ay t"at it "as a "eadin!, a "oriJontal r+le, t"ree lin s and a p"oto of yo+r instit+tion& %lso, *rite t"ree <(M# doc+)ents for t"e lin s& '-34: Nrepare a <(M# pa!e listin! pop+lar car co)panies& Oor eac" co)pany prepare a s+b-list s"o*in! ,ario+s brands of cars it offers& '-35: -rite a <(M# doc+)ent to dra* t"e follo*in! table& %rea %nnana!ar %dyar E!)ore Nrices of flats in C"ennai 2335 (ype of "o+se Ordinary Del+x Ordinary Del+x Ordinary Del+x /ate in r+peesDsA& ft& 1=33 1>43 2243 2;;4 2333 2124

'-3;: -rite a <(M# doc+)entDpa!e t"at "as 3 fra)es& ("e *indo* )+st be ro* *ise di,ided into t*o fra)es first and t"e botto) fra)e is di,ided into t*o fra)es col+)n *ise& '-3=: -rite a <(M# doc+)ent s"o*in! a pass*ord field& -"en pass*ord is entered, t"e asteris sy)bols )+st be displayed in place of pass*ord in t"e inp+t field& '-3>: Desi!n t"e follo*in! for) +sin! <(M#&

A&&#!1a !(n '() A2+!$$!(n @a)e DO6 O Male O Oe)ale


SUBMIT

'-23: -rite <(M#DPa,ascript code for t"e pa!e s"o*in! c"ec boxes, text box and s+b)it b+tton& ("e +ser selects t"e c"ec box7es9 and once t"e +ser clic s s+b)it b+tton t"e selected c"ec box ite)s appear in t"e text box& '-21: -rite <(M#DPa,ascript code for t"e pa!e s"o*in! c+rrency con,ersion& ("e +ser enters t"e a)o+nt in r+pees in t"e text box and selects a patrtic+lar radio b+tton for t"e c+rrency con,ersion& On c"ec in! it )+st display t"e a)o+nt in t"e correspondin! c+rrency& '-22: -rite <(M#DPa,ascript code for t"e pa!e s"o*in! a select box and a text box& ("e select box contains a list of na)es& -"en t"e +ser selects a na)e fro) t"e select box t"e correspondin! p"one n+)ber appears in t"e p"one n+)ber inp+t box& '-23: -rite <(M#DPa,ascript code for t"e pa!e "a,in! t"ree text boxes and a s+b)it b+tton& ("e t"ree text boxes are e)ail id, a!e and na)e& ("e e)ail id text box "as to contain S sy)bol, a!e s"o+ld be !reater t"an 1 and less t"an or eA+al to 133 and na)e s"o+ld not exceed 13 c"aracters& ?f t"e e)ail id doesnot contain S sy)bol an alert )essa!e is fired& $i)ilarly for a!e and na)e t"e corresponfin! alert )essa!e is fired&

Você também pode gostar