2. Specification. A secure research facility has hired

Added on - 21 Sep 2019

  • 15

    pages

  • 3388

    Words

  • 77

    Views

  • 0

    Downloads

Showing pages 1 to 4 of 15 pages
2.SpecificationAsecureresearchfacilityhashiredyoutodevelopanewsystemfortheliftsof itssecurebuilding.Thesystemneedsto knowwhereeveryoneinthebuildingisat everymoment.Tousethelifts,apersonmustbeaddedto thesystemandgivenanIDcard.ThisID cardmustbeswipedwhenmakinga tripontheliftso thattheliftcantrackthemovementof thatperson.Thebuildinghas6floorsand3 lifts.Eachliftservicesadifferentrangeof levels:Lift1serviceslevels16,Lift2 serviceslevels26 andLift3 serviceslevels25. Thebuildingentranceisonlevel2andtheinitialrestingpositionsof all 3 liftsislevel2.WhenapersonregistersforanID card,thesystemrecordstheirinitiallevelas2. A personcanalsoberemovedfromthesystem,butonlyif theyareonlevel2 andnotcurrentlywaitingfororaboardalift.Whencallingalift,apersonswipeshis/herID card,selectsa destinationlevel/floor,andthenwaits.Thesystemusesanalgorithmto selectthemostsuitableliftandreportsthenumberofthatlifttothecaller.Whentheliftreachesthecaller’scurrentlevel,thecallerboardstheliftunlesstheliftisheadingin theoppositedirectionto thatof thecaller’sdestination.Whentheliftreachesthecaller’sdestination,thecalleralightsfromthelift.Theliftwillstopat alevelifanypersonwantsto boardoralight.1Themostsuitableliftforacallerisdeterminedbya suitabilityfunction.If a lift’sservicerangedoesn’tincludethecaller’scurrentlevelordestinationlevel,thatlift’ssuitabilityis0.Otherwiseifaliftismovingawayfromthecaller,itssuitabilityis1. Otherwiseif a liftismovingintheoppositedirectionthatthecallerwantsto goin,thenitssuitabilityisN +1DwhereNisthehighestminusthelowestlevelof thebuildingandD isthedistancein levelsbetweentheliftandthecaller.Otherwise,thelift’ssuitabilityisN +2D. Themostsuitableliftforacalleristheliftwiththehighestsuitability.Anaside...
Whilereadingthethefirstpartof thespecification,youwillnoticethereisa lotgoingon.● Howmanyfunctionsdidyouidentify?● Howmanyclassesdidyouidentify?● Whatarethefieldsin eachclass?● Howmanygoalsdidyouidentify?● Howmanypatternsdidyouthinkof thatmightbeapplicable?Thisassignmentwillbechallengingandyouwillprobablywantto manageyourtimewell.● Howlongdoyouthinkit willtakeyouto codethefunctions?● Howlongdoyouthinkit willtakeyouto codeeachgoal?Agoodruleofthumbistothinkof anestimate,andthenmultiplythatnumberby3 or 4!Tomanageyourtimewell,youmayneedto figureoutwhichpartsof theassignmentyoucanstartearly.● Whichpartscanyoustartnow?● Whichpartscanyoustartin week5?Ifyoucompletepartsinthesameweekthatyoulearnthetopics(whiletheyarefreshin yourmind),theywilltakelesstimeto complete.TheUserInterfaceBelowisasampleI/Otrace.Noteveryconceivablescenarioisshownbelowandyoushouldsubmityourcodeto PLATEtoseewhatspecificscenariosaretested.BasicusageWhentheprogramlaunches,youwillseea modepromptwhichcanbeusedto changethebehaviouroftheprogram.Mode:Forthemoment,let’sleavethisblankandpressenter.Themenuisnowshown.Inputtinganunrecognisedcommandresultsin thehelpbeingshown:Choice(a/r/p/c/l/o/x):?2Menua=addperson
r=removepersonp=showpeoplec=callliftl=showliftso=operateTheusercanadd,removeandshowpeopleregisteredin thesystemwiththe‘a’,‘r’ and‘p’options.Eachpersonmusthavea uniqueID:Choice(a/r/p/c/l/o/x):aPersonID:1Name:SamWorthingtonChoice(a/r/p/c/l/o/x):aPersonID:1IDalreadyexistsChoice(a/r/p/c/l/o/x):aPersonID:2Name:NicoleKidmanChoice(a/r/p/c/l/o/x):aPersonID:3Name:HughJackmanChoice(a/r/p/c/l/o/x):pSamWorthington(1)onlevel2NicoleKidman(2)onlevel2HughJackman(3)onlevel2Choice(a/r/p/c/l/o/x):rPersonID:1Choice(a/r/p/c/l/o/x):rPersonID:1NosuchpersonChoice(a/r/p/c/l/o/x):pNicoleKidman(2)onlevel2HughJackman(3)onlevel2
Theliftsareshownwiththe‘l’ option:Choice(a/r/p/c/l/o/x):lLift1|0|Lift2|0|Lift3|0|Eachliftisdisplayedasa stringof dasheswiththeleftsiderepresentingthebottomof theliftandtherightsiderepresentingthetopof thelift.Oneof thedashesisreplacedbya numberindicatinghowmanypassengersarecurrentlyaboardthatlift.Thepositionof thisnumberalsoindicatesthelocationof theliftwithintheshaft.NoticethatLift2 andLift3 areshiftedrightbyonelevelbecausethoseliftsstartat level2. Yourcodemustnothaveanyspecialcasestodealwithdifferentlifts.Forexample,youcannotwritecodelikethis:if (liftNumber!=1){addanextraspace}.3Aliftcanbecalledwiththe‘c’ option:Choice(a/r/p/c/l/o/x):cPersonID:1NosuchIDChoice(a/r/p/c/l/o/x):cPersonID:2Destinationlevel:4Choice(a/r/p/c/l/o/x):pNicoleKidman(2)onlevel2waitingtogotolevel4HughJackman(3)onlevel2Choice(a/r/p/c/l/o/x):lLift1|0|Lift2|0|Lift3|0|Themostsuitableliftischosenandthecallerisaddedto thelift’squeue.In thiscase,all 3liftsareequallysuitableso thefirstliftwillbechosen.If therewasnosuitableleft(e.g.thedestinationwasnotserviceablebyanylift),thecallisdiscarded.Theliftsareoperatedviathe‘o’option.Here,eachliftusethisalgorithm:
desklib-logo
You’re reading a preview
card-image

To View Complete Document

Become a Desklib Library Member.
Subscribe to our plans

Download This Document