Coding
Microsoft Word - Project 2 Simon Says.docx Project2:SimonSays YourtaskforthisprojectistowriteaSimonSaysgame.Theprogramshouldgeneratean ever-increasingsequenceofrandomvalues,andtheuserneedstotypeinthesequence.The gameshouldhavethreedifficultylevels:easy(colors),medium(digits)andhard(letters). Atthebeginningofeachround,theprogramshouldasktheuserwhichdifficultylevelthey wanttoplayat.Attheendofeachround,itshouldtellthemthelengthofthelongest sequencetheyenteredcorrectlybeforemessingup.Anexamplewillhopefullymakethis moreclear: Which difficulty level do you want: easy, medium, or hard? potato That is not a valid difficulty level! Which difficulty level do you want: easy, medium, or hard? easy Simon says: red (The program should then pause for 2 seconds and then write out 200 blank lines so that the screen is empty.) Input: red Right! Your score is 1. Simon says: red green (The program should then pause for 2 seconds and then write out 200 blank lines so that the screen is empty.) Input: red blue Incorrect! Your score for this round was 1. Do you want play again (yes or no)? potato That is not a valid answer! Do you want to play again? no Ok, goodbye! Ontheeasymode,yourprogramshouldrandomlychoosebetweenfourcolors:red,green, yellowandblue.Inmediummode,itshouldrandomlychoosedigitsbetween1and9, inclusive(e.g.amediumsequencemightbe1 9 8 3 9 9).Inhardmode,itshould randomlychooselowercaseletters(e.g.t e v b w t a).Whencheckingauser’sanswer, spacingandcapitalizationshouldbeignored(e.g.ifthesequenceisred green red red blueandtheusertypesRedgreenredredblue,thatshouldbecountedascorrect.)As shownintheexampleabove,besuretohandleinvaliduserresponsestoquestionsabout thedifficultylevelandplayingagain. Hints OnewaytoapproachthiswouldbetostorethesequenceSimonissayinginastringand thenusetheStringclass’sequalsmethodtocomparewhattheuserenterstothecorrect sequence.RecallthattheStringclasshasmanyusefulmethods,suchasequalsIgnoreCase (usefulforignoringdifferencesincapitalizationwhencomparingtwostrings)andreplace (usefulfor,amongotherthings,removingspacesfromwithinastring). ThestatementThread.sleep(2000);willcauseaJavaprogramtopausefortwo secondsbeforecontinuing.Tousethismethodfromwithinmain,youneedtomakeaslight changetothewayyourmainmethodisdeclared: public static void main(String[] args) throws Exception Recallthattogeneratearandomnumberbetween1and10inclusive,youcanuse: int randNum = (int) ((Math.random() * 10) + 1); Youcandomathwithcharacters,whichmightbehelpfulwhengeneratingarandom sequenceofletters.Forexample: char letter = ‘a’; letter = (char) (letter + 4); // letter is now ‘e’ Rubric Projectsthatdon’tcompilewillreceiveazero. [10pts]Theusercanchoosethedifficultylevel,andinvalidchoicesarerejected. [15pts]Easymodeworksasdescribed. [15pts]Mediummodeworksasdescribed. [15pts]Hardmodeworksasdescribed. [10pts]Spacingandcapitalizationareignored. [5pts]Theuser’sscoreisdisplayedattheendofeachround. [10pts]Theusecanchooseiftheywanttoplayagain,andinvalidchoicesarerejected. [20pts]Theprogramisclearlyorganized,commented,andfollowsstandardcoding practices,includingvariableandclassnames.