Microsoft Word - HalloweenPartyAssignment.docx ProgrammingandLogicI HalloweenPartyCountAssignment Createaprogramcalled PartyCount.java. Myprogram would...

1 answer below »
I have attached file for a programming assignment.


Microsoft Word - HalloweenPartyAssignment.docx ProgrammingandLogicI HalloweenPartyCountAssignment CreateaprogramcalledPartyCount.java.Myprogram would beConwayPartyCount.javaandmyclassnamewouldbe ConwayPartyCount. Halloweenisalmosthereandyouwanttogetaheadcountofthepeopleinvitedtoyour party.Youhavearawdatafilewiththenamesofthepeoplecoming,thenumberofpeople theyarebringing,andthefoodtheysigneduptobring. YourprogramwillreadfromafilecalledpartyResponses.txt,countthenumberofpeople comingandmaintainalistofthefood.Hardcodethisfilenameintoyourprogram. Beforeyoubeginyourprogram,makesureyouimportjava.util.Scannerandjava.io.*. ThemainmethodshouldthrowIOException. YouwillneedthreeStringvariables:onetoreadtheguest’sname,onetoreadthefood,and onetokeepthefoodlist.Initializethefoodlisttotheemptystring:String foodList = “”;Youwillneedtwointvariables:onetoreadthecountandoneaccumulatortokeep trackofthenumberofguestscomingtotheparty.Initializetheaccumulatorto0beforethe loopbegins. Thefileyouarereadingfromshouldexist,butmakesureitdoesexistbeforetryingtoopen itwiththeScanner.Callthefileobject’sconstructormethodandsenditthefilename.(This calldoesnotthrowanexception.)Thenuseanifstatementandinthecondition,callthe Filemethodexists().Therearetwooptions.Thefirstmaybeeasier–checkifthefiledoes notexist,andinthecondition-if-truecallSystem.exit(0).Thisendstheprogram.The secondoptionistocheckifthefiledoesexistandputtherestofthecodeinsidetheif condition-if-true. Ifthefileexists,yourprogramisgoingtotraversethecontentsofthefile.Useawhileloop. Intheconditionofthewhileloop,calltheScanner’shasNext()method.Thismethod returnstrueifthereismoredatainthefileandfalseifthereisnomoredatainthefile.It doesnotadvancethereadpositionofthefile. Theinputfilecontainsanumberoflines.Eachlinecontainsaguest’sname,thenumberof peopletheyarebringing(includingthemselves)andthefoodtheyarebringing.Youwon’t knowhowmanylinestheinputfilecontainsbutyoucanassumethateverylinewillfollow thisformat. Forexample: Raven 1 ghost cookies Ichabod 1 pumpkin pops Frankenstein 2 nothing TheformatofthefileIusetotestwillbethesame,butthevalueswillbedifferent. Insidetheloop,thesequenceofreadsisasfollows:usethenext()methodtoreadthename, nextInt()toreadthecount,thennextLine()toreadtherestoftheline.These3methodcalls canbethefirstthreelinesofcodeinsidetheloop. Asyourprogramtraversesthroughtheinputfile,itwillkeeptrackofallthepeoplecoming tothepartyandallthetreatstheyarebringing.Thisisaccomplished,afterreadinginthe data,byupdatingyourtotalcountvariablewiththenumberofpeopleintheparty,andby addingthetreattotheStringcontainingthelistoftreats. Ifaparticularparty-goerisbringingfood,thefoodislistedintheinputfileafterthenumber ofpeopleintheparty.Iftheparty-goerisnotbringinganything,thatfoodislistedas “nothing”.Wedon’twanttoadd“nothing”toourlistoffood. AfterreadinginthefoodtoaStringvariable,checkifthatstringvariableequalstheword “nothing”andonlyaddittothefoodlistifitdoesnotequal“nothing”.Usethestring methodequals()tocomparethestrings.However,becauseofthewaynextLine()works (explainedinLectureModule3),thestring“nothing”mightactuallybe“nothing”(orhavea spacebeforethen).So,inactuality,youarecomparingthefoodthefriendisbringingto “nothing”. Ifthefooddoesnotequal“nothing”,youaddittothelist,whichisjustabigstringwithall thefoodtheguestsarebringing.Usingthecombinedconcatenationoperatorhere(+=)is thewaytoaccomplishthis.But,tomakethelistmoreeasilyreadable,afterconcatenating thefooditemtothelist,concatenatethenewlinecharacter.Theneachfoodwillbeprinted onitsownline. Aftertheloopends,printthenumberofpeoplecomingtothepartyandthelistofgoodies. Asamplerun: Copyright Policy: The copy in this document has been provided for educational purposes in accord with copyright law. This material is protected by copyrights owned by the instructor. The user of this work is responsible for adhering to copyright law. This material cannot be re-published, uploaded, posted, transmitted or distributed in any way. Microsoft Word - HalloweenPartyAssignment.docx ProgrammingandLogicI HalloweenPartyCountAssignment CreateaprogramcalledPartyCount.java.Myprogram would beConwayPartyCount.javaandmyclassnamewouldbe ConwayPartyCount. Halloweenisalmosthereandyouwanttogetaheadcountofthepeopleinvitedtoyour party.Youhavearawdatafilewiththenamesofthepeoplecoming,thenumberofpeople theyarebringing,andthefoodtheysigneduptobring. YourprogramwillreadfromafilecalledpartyResponses.txt,countthenumberofpeople comingandmaintainalistofthefood.Hardcodethisfilenameintoyourprogram. Beforeyoubeginyourprogram,makesureyouimportjava.util.Scannerandjava.io.*. ThemainmethodshouldthrowIOException. YouwillneedthreeStringvariables:onetoreadtheguest’sname,onetoreadthefood,and onetokeepthefoodlist.Initializethefoodlisttotheemptystring:String foodList = “”;Youwillneedtwointvariables:onetoreadthecountandoneaccumulatortokeep trackofthenumberofguestscomingtotheparty.Initializetheaccumulatorto0beforethe loopbegins. Thefileyouarereadingfromshouldexist,butmakesureitdoesexistbeforetryingtoopen itwiththeScanner.Callthefileobject’sconstructormethodandsenditthefilename.(This calldoesnotthrowanexception.)Thenuseanifstatementandinthecondition,callthe Filemethodexists().Therearetwooptions.Thefirstmaybeeasier–checkifthefiledoes notexist,andinthecondition-if-truecallSystem.exit(0).Thisendstheprogram.The secondoptionistocheckifthefiledoesexistandputtherestofthecodeinsidetheif condition-if-true. Ifthefileexists,yourprogramisgoingtotraversethecontentsofthefile.Useawhileloop. Intheconditionofthewhileloop,calltheScanner’shasNext()method.Thismethod returnstrueifthereismoredatainthefileandfalseifthereisnomoredatainthefile.It doesnotadvancethereadpositionofthefile. Theinputfilecontainsanumberoflines.Eachlinecontainsaguest’sname,thenumberof peopletheyarebringing(includingthemselves)andthefoodtheyarebringing.Youwon’t knowhowmanylinestheinputfilecontainsbutyoucanassumethateverylinewillfollow thisformat. Forexample: Raven 1 ghost cookies Ichabod 1 pumpkin pops Frankenstein 2 nothing TheformatofthefileIusetotestwillbethesame,butthevalueswillbedifferent. Insidetheloop,thesequenceofreadsisasfollows:usethenext()methodtoreadthename, nextInt()toreadthecount,thennextLine()toreadtherestoftheline.These3methodcalls canbethefirstthreelinesofcodeinsidetheloop. Asyourprogramtraversesthroughtheinputfile,itwillkeeptrackofallthepeoplecoming tothepartyandallthetreatstheyarebringing.Thisisaccomplished,afterreadinginthe data,byupdatingyourtotalcountvariablewiththenumberofpeopleintheparty,andby addingthetreattotheStringcontainingthelistoftreats. Ifaparticularparty-goerisbringingfood,thefoodislistedintheinputfileafterthenumber ofpeopleintheparty.Iftheparty-goerisnotbringinganything,thatfoodislistedas “nothing”.Wedon’twanttoadd“nothing”toourlistoffood. AfterreadinginthefoodtoaStringvariable,checkifthatstringvariableequalstheword “nothing”andonlyaddittothefoodlistifitdoesnotequal“nothing”.Usethestring methodequals()tocomparethestrings.However,becauseofthewaynextLine()works (explainedinLectureModule3),thestring“nothing”mightactuallybe“nothing”(orhavea spacebeforethen).So,inactuality,youarecomparingthefoodthefriendisbringingto “nothing”. Ifthefooddoesnotequal“nothing”,youaddittothelist,whichisjustabigstringwithall thefoodtheguestsarebringing.Usingthecombinedconcatenationoperatorhere(+=)is thewaytoaccomplishthis.But,tomakethelistmoreeasilyreadable,afterconcatenating thefooditemtothelist,concatenatethenewlinecharacter.Theneachfoodwillbeprinted onitsownline. Aftertheloopends,printthenumberofpeoplecomingtothepartyandthelistofgoodies. Asamplerun: Copyright Policy: The copy in this document has been provided for educational purposes in accord with copyright law. This material is protected by copyrights owned by the instructor. The user of this work is responsible for adhering to copyright law. This material cannot be re-published, uploaded, posted, transmitted or distributed in any way.
Answered Same DayOct 17, 2021

Answer To: Microsoft Word - HalloweenPartyAssignment.docx ProgrammingandLogicI...

Anurag answered on Oct 18 2021
123 Votes
chris cole's project/.classpath

    
        
            
        
    
    
    
chris cole's project/.project

     chris cole's project
    
    
    
    
        
             org.eclipse.jdt.core.javabuilder
            
            
        
    
    
         org.eclipse.jdt.core.javanature
    
chris cole's...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here