Vous êtes sur la page 1sur 2

301038PPPRACTICALEXERCISES

DueFriSep012017atMidnight
Releasedon24/7/2017,lastmodifiedandfinalisedonxx

PREAMBLE
1.Overthesemester,youwillbeworkinginagroupoftwo,eventhoughthis1stassignmentisan
individualone.
2.Thisassignment1isworth20%ofthetotalmarksforthisUnit,anditiscomposedmainlyofthe
questionstakendirectlyfromthecoveredchaptersoftheprescribedtextbook.
3.Qualityofthework,includingsuchasproperprogramdesignandcodingstyleand
documentation/comments,willalsobeamajorfactorofconsiderationforthetopgrades.
4. Itisbestthattheassignmentquestionsbelowcorrespondingtoeachchapterinthetextbook
beworkedonandsolvedduringthelabpracticalforthatchapter,orinthenextfewdays
immediatelyafterwards.

QUESTIONS
1.(PP1.10,p.82)(2marks)Writeaprogramthatdisplaystheword"HI"inlargeblockletters.Make
eachlargeletteroutoftheothercharacterasshownbelow.
III III HHHHHHHHHHH
III III HHH
III III HHH
IIIIIIIIIIII HHH
III III HHH
III III HHH
III III HHHHHHHHHHH

2.(PP2.7p.135)(3marks)Writeaprogramthatpromptsforandreadsintegervaluesfortypingspeed
andnumberofcharactersinthedocument,thenprintsthetimerequiredtotypethemasafloating
pointresult.
3.(PP3.9,p.184,modified)(3marks)Writeaprogramthatgeneratesarandomintegerbase(b),height
(h)andaside(a)foraparallelogramintherange10to30,inclusive,andthencomputesthe
permimeterandthesquarerootoftheareaoftheparallelgram
Area=baseheight,Perimeter=2(a+b)
Writeaprogramthatgeneratestworandomintegersintherange1to20,exclusive,anddisplaysthe
sineandcosineofthesumofthosetwointegers.
4.(PP4.4,p.228)(3marks)WriteaclasscalledDogthatcontainsinstancedatathatrepresentsthe
dog'snameandage.DefinetheDogconstructortoacceptandinitialiseinstancedata.Includegetter
andsettermethodsforthenameandage.Includeamethodtocomputeandreturntheageofthedogin
"Personyears"(seventimesthedog'sage).IncludeatoStringmethodthatreturnsaoneline
descriptionofthedog.CreateadriverclasscalledKennel,whosemainmethodinstantiatesand
updatesseveralDogobjects.YoumayuseDoginsteadofKennelasyourdriverclassifyouwish.
5.(PP5.4,p.290,modified)(3marks)WriteaprogramthatplaystheHiLoguessiggamewith
numbers.Theprogramshouldpickarandomnumberbetween10and90(inclusive),thenrepeatedly
prompttheusertoguessthenumber.Oneachguess,reporttotheuserthatheorsheiscorrectorthat
theguessishighorlow.Continueacceptingguessesuntiltheuserguessescorrectlyorchoosetoquit.
Useasentinelvaluetodeterminewhethertheuserwantstoquit.Countthenumberofguessesand
reportthatvaluewhentheuserguessescorrectly.Attheendofeachgame(byquittingoracorrect
guess),prompttodeterminewhethertheuserwantstoplayagain.Continueplayinggamesuntilthe
userchoosestostop.WenotethatPalindromeTester.java(seeListing5.9ofthetextbook)and
Guessing.java(seeListing5.5ofthetextbook)canofsomeassistance.
6.(PP4.9,p.229)(3marks)UsingtheDieclassdefinedinChapter4,writeaclasscalledPairOfDice,
composedoftwoDieobjects.Includemethodstosetandgettheindividualdievalues,amethodto
rollthedice,andamethodthatreturnsthecurrentsumofthetwodievalues.Createadriverclass
calledRollingDice2toinstantiateanduseaPairOfDiceobject.
7.(3marks)SimilartotheabovePairOfDice,writeaclasscalledMultiDice,composedofany
numberofDieobjects.UseArrayListtokeepalltheDieobjects,anduseaconstructortoconstruct
suchalistofobjects.Includeamethodthatdisplaysallthedievalues,andanothermethodthat
calculatesthesumofallthedievalues.Writeadriver/mainmethodtocreatealistof10dice,andthen
displaytheirrespectivevaluesandthesumoftheirvalues.

SUBMISSION
ThesubmissionshouldcontainalltheJavasourcecode,infilesdirectlycompilable,andaMicrosoft
Worddocumentthat,questionbyquestion,listtheJavasourcecode(notasscreenshots)aswellasthe
screenshotsofthecorrespondingexecutionresult.Pleasenotethatthescreenshotsmustbeeasily
readablewhenprintedout.
Zip(don'tusetherarcompressionformat)alltherelevantfilesintoasinglezipfile,andthenuploadit
viathesubmitbuttonontheunitwebsite.it'seachstudent'sresponsibilitytokeepthesubmission
receiptwhichwillbeautomaticallygeneratedaftereachsubmission.

Vous aimerez peut-être aussi