Menu

[Solved]9 Points Project Race Names Monday March 4 Tuesday March 5 Duplicate Character Games Outpu Q37203217

(9 points) Project Race names:Monday March 4 Tuesday March 5(Duplicate Character games output on mywebsite)The game will use the random number generator ofthe Math class to repeatedly assign to each name a number. Thesenumbers are used by the names to move closer to the finish line.(You can decide the range of the numbers.) Use the codeThread.sleep(1000); to stop the program for a short time as itruns. The argument is in milliseconds. 1000 is one second. Bycarefully adjusting the number of “n”, the movement of the namesappear to move in a race. I used 7 methods. Here are someadditional comments on the NameRace() class:

  1. You do not need to name it NameRace. I did not call it that butit would make a good name for the class.
  2. The DescriptiveName class that I gave as an example gives anoutline for this game.
    1. There is a public method that is called from the GamesDemoclass when this game is picked from the menu. Give this method aname appropriate for the Name Race game.
    2. There is an introduction method describing the game. I give thetext that you can use on my web site. You do not need to use mytext but it should be descriptive of the game
    3. There is a while loop that allows the player to continueplaying this game.
    4. There are other methods in this class that are used. Thesemethods break the code up into logical segments and can be calledfrom the public method to run the code.
    5. My solution has about 130 lines of code. There are 5 helpermethods besides the introduction method that are called to run thegame. These are private as is the introduction method.
  3. You must understand what the program is to do. From my outputon my website it is hard to see how the game would look. When thisgame is run the names appear to move from left to right. Thisinvolves the String methods making it appear that the three namesare moving. The three names move as a group. After each group moveI figured out the number of calls to Sysyem.out.println() to makeit appear that the names stayed in the same place on the screen. Idemonstrate this in the introduction method of the menu class. Itlooks like this: System.out.println(“nnnnnnnnnnnnnnnn”   );
  4. Here is a most basic algorithm:
    1. print introduction
    2. Within a loop, allow the client to race as many races as hewishes.
  5. Part two of the algorithm requires a second loop. This meansyou will use a loop in a loop. (Page 216 gives a while loop in ado-while. DescriptiveMethod() in the DescriptiveName class uses awhile loop as the outer loop. You can use either one.)
  6. Start thinking about the variables you will need. This is veryimportant! You want to imagine the variables being manipulated asthe code is running.
    1. There are 3 names. I used Jim, Sue, and Tom. Any names will do.Use your own name and think of two other names with the same numberof characters. (If the number of characters in the names isdifferent the longer name will have an advantage.)
    2. Pick a distance for the race. This will be recorded in yourprogram as a number of characters. The length of the race can beabout the width of the screen. The display monitor on my classcomputer does not hold the complete race as I programmed it. (Myhome computer has a wider screen.)
    3. In my solution each name needs an integer variable to keeptrack of its distance and a String variable that will grow inlength as the game progresses.
    4. I used a boolean variable raceIsDone as the control variablefor the inner while loop.
    5. These variables are GLOBAL and declared as static variables andplaced inside the NameRace class, and for convenience are placedabove the methods of the class. When declared as global they areaccessible to all the methods of the class. The one public methodis called from the Menu class and in its first loop initializes thevariables to starting values for a race.   If the clientwishes to race again, these variables will be re-initialized forthe next race.
  7.   The algorithm for a single race might go like this:
    1. Set the stage for a race. I have a method that I call to dothis. (See the output on my website.)
    2. While the race is not done:
      1. For each name:
        1. get a number from the random number generator for a move
        2. Add this number to the integer value used to keep track of thedistance this name has gone
        3. Create a string that will have this many characters in it. Mostof the characters will be blank with the name at the end.
        4. Subtract this number from the integer value used to track thedistance this name needs to go and create a string of this manycharacters.
        5. System.out.println() these two strings with the vertical linekey.
      2. Check to see if a name won the race. If it does, set theboolean variable to true and print the name that won the race.(There could be more than one winner if there is a tie.)
  8. I combined items i and ii into one method. This method callsthree methods, one for each name that implements item ii. Thesethree methods are almost exactly alike.
  9. Besides printing blank lines to make the names appear in thesame place on the screen after each move this program also insertslines that stop the program from running for short periods of time.The line of code that does this is: Thread.sleep(500); This linestops the program for a half second. With an argument of 1000 itwould be a second. Programs that use the method sleep() from theThread class must indicate that an exception may be thrown. Thecode throws InterruptedException was placed at the end of three ofthe methods. See the DescriptiveName class for examples of this. Iput 2 seconds before the game started and .7 second after eachmove. Play with it and see how fast you would like your names tomove. The sleepDemonstration() method in the DescriptiveName classalso demonstrates the random number generator. There it created aninteger number from 1 to 6. You can experiment with differentvalues for your NameRace class. I used numbers from 1 to 5.
  10. Start writing this solution a little at a time. Get each partyou write to compile and run before you go on to the next part. UseSystem.out.println() to print values of variables to follow thelogic of your code.
  11. This third game has the end of the race marked for each name.This requires the strings that are printed with each set of movesto maintain their end line as the names progress across thescreen.

Expert Answer


Answer to (9 points) Project Race names: Monday March 4 Tuesday March 5 (Duplicate Character games output on my website)The game w… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *