Fall XXXXXXXXXXLab 4 Create a Java class with a main method that prompts the user to ask any yes/no question, then generate a random boolean which displays "Yes!" if true, and displays "No." if false....

Java


Fall 2021 - Lab 4 Create a Java class with a main method that prompts the user to ask any yes/no question, then generate a random boolean which displays "Yes!" if true, and displays "No." if false. Wrap this in a loop that repeatedly asks and answers questions. When the user presses enter without any text, break out of the loop. Hints: • Use nextLine() with Scanner to accept a multi-word answer. • Check for a blank answer by comparing the String entered with .equals("") • If the String entered equals "", use the break statement to break out of the loop. • Use nextBoolean() with Random to randomly generate true or false • Remember to import java.util.Scanner and java.util.Random, then create Scanner and Random objects in your main method as taught in class.` CS 1341 Lab 4 Fall 2021 Pre-lab (10 pts) The pre-lab is due during at the beginning of your lab class during the week of Oct 4 - Oct 8, 2021. > java Wizard Omnicient Wizard Ask me any yes/no question: Will I become rich? No. Ask me any yes/no question: Will I become famous? Yes! Ask me any yes/no question: Will I travel the world? No. Ask me any yes/no question: > Match the sample output below: Magic 8 Ball (20 pts) Shake the Magic 8 Ball to get answers to life's most pressing questions! Using a copy of your solution to the pre-lab, enhance it to create a Magic 8 Ball program that includes an array containing multiple possible answers to questions. You will also create a second method that returns a randomly selected answer (as a String) to print from the main method. Feel free to use this list of 20 possible answers, or make up your own if you prefer: • Reply hazy • Ask again later • Better not tell you now • Cannot predict now • Concentrate and ask again • Don't count on it • My reply is no • My sources say no • Outlook not so good • Very doubtful • It is certain • It is decidedly so • Without a doubt • Yes definitely • You may rely on it • As I see it, yes • Most likely • Outlook good • Yes • Signs point to yes Detailed instructions on the next page Note: Sharing these instructions with anyone other than an SMU CS Teaching Assistant or Senior Mentor, or ALEC tutor (or another tutor pre-approved by your instructor), posting on any website, or submission of any part of a solution that was created by anyone other than you constitutes an SMU honor code violation. Lab (Three Problems for total of 90 pts) Write the complete solutions for the Magic8Ball 20 points) , PassRun1 (35 points) and PassRun2 (35 points) following the instructions on the following pages. The grading rubric is integrated with the instructions. Ensure that your program compiles properly with no syntax errors and submit the .java and .class files to Canvas to receive full credit. The lab is due Saturday Oct 23, 2021 at 6:00am CST Magic 8 Ball (continued) > java Magic8Ball I AM THE MAGIC 8 BALL Ask me a question about your future: Will I be rich? My reply is no Ask me a question about your future: Will I find happiness? Reply hazy Ask me a question about your future: Will I live to be 150? It is decidedly so Ask me a question about your future: Will my hair turn gray? You may rely on it Ask me a question about your future: Will I graduate? Better not tell you now Ask me a question about your future: > Format your print statements to match the sample output below: Create Scanner Display welcome message Loop Prompt "Ask me a question about your future" If the answer is blank ("") break out of the loop and exit the program Otherwise, call the getAnswer method, which returns a String. Print that answer Repeat the loop main method 5 points Create Random object Create a String array containing the values shown in the instructions on the previous page Generate a random number in the range 0-19 Return the String found in the array at index location of the random number getAnswer method 5 points No parameters Magic8Ball class 10 points: Compiles without syntax errors and both .java and .class files submitted. Comments are included before each method and loop describing what function that method or loop performs. Pass Run Version 1 (40 pts) This is the first of multiple labs with multiple versions of a Football scrimmage game. You don't have to have expert knowledge of the game of American Football for these labs, but a basic understanding will be helpful. For this version, the objective is start on your 20 yard line and move the ball 80 yards down the field to score a touchdown. You are the quarterback, and for each play, choose whether to pass the ball downfield to be caught or hand it to another player to run with the ball. If you choose to pass, a successful catch can result in as many as 25 yards toward the goal. However, a pass play also increases the likelihood of getting tackled (sacked) before the ball is thrown, resulting in no forward progress or even moving backward from where you started. You will use a random number to select from a set of these 10 possible results: -10 -5 0 0 0 5 10 15 20 or 25 If you choose a run play, there is a greater likelihood of making forward progress than with a pass play, however the distance traveled will be shorter. For a run play, you will use a random number to select from this set of 10 possible results: - 5 -3 -1 1 2 4 5 6 8 or 9 Move the ball 80 yards forward to score Pass Run Version 1 (continued) PassRun1 class main method 20 points Declare an integer variable to contain current location and initialize it to 20 Print a message displaying the starting location Loop: Prompt the user to Pass, Run or Quit If the user chooses Quit, break out of the loop Otherwise, call the getYardsMoved method passing "P" for Pass or "R" for Run Use the value returned from getYardsMoved to update the location Display the new location and continue the loop 10 points: Compiles without syntax errors and both .java and .class files submitted. Comments are included before each method and loop describing what function that method or loop performs. Declare an initialize a static Scanner variable and a static Random variable that can be used in both methods (remember to include an import statements for Scanner and Random) getYardsMoved method 20 points One parameter: String containing either a P or an R Return the int containing the positive or negative number with total yards moved Create an int array containing the 10 possible pass values Create another int array containing the 10 possible pass values Generate a random number in the range of 0-9 to use as a random index number in the array corresponding to the selected play type (P or R) If the method's parameter contains "P", Retrieve a random value from the pass values array. If the method's parameter contains "R", Retrieve a random value from the run values array. Pass Run Version 1 (continued) > java PassRun1 Starting at the 20 yard line Pass, Run, or Quit (P/R/Q)? p Moved -10 yards. New location is 10. Pass, Run, or Quit (P/R/Q)? p Moved 0 yards. New location is 10. Pass, Run, or Quit (P/R/Q)? p Moved -10 yards. New location is 0. Pass, Run, or Quit (P/R/Q)? p Moved 10 yards. New location is 10. Pass, Run, or Quit (P/R/Q)? p Moved -5 yards. New location is 5. Pass, Run, or Quit (P/R/Q)? p Moved 0 yards. New location is 5. Pass, Run, or Quit (P/R/Q)? p Moved 15 yards. New location is 20. Pass, Run, or Quit (P/R/Q)? p Moved 20 yards. New location is 40. Pass, Run, or Quit (P/R/Q)? r Moved 2 yards. New location is 42. Pass, Run, or Quit (P/R/Q)? r Moved -1 yards. New location is 41. Pass, Run, or Quit (P/R/Q)? r Moved 5 yards. New location is 46. Pass, Run, or Quit (P/R/Q)? r Moved 8 yards. New location is 54. Pass, Run, or Quit (P/R/Q)? r Moved 1 yards. New location is 55. Pass, Run, or Quit (P/R/Q)? p Moved 10 yards. New location is 65. Pass, Run, or Quit (P/R/Q)? p Moved -10 yards. New location is 55. Pass, Run, or Quit (P/R/Q)? q Format your print statements to match the sample output below: Pass Run Version 2 (30 points) Create a copy of PassRun1 called PassRun2 and make the following three revisions to it: Revision 1: Create another loop inside the loop in your main method that rejects any entry that is not P, R or Q. If anything is entered other than those three values, print an error message and repeat the prompt until a valid value is entered. When a valid value is entered, break out of this inner loop. Revision 2: When the value is returned by getYardsMoved, if the new value is less than 0, set it to 0 (you can't land behind the 0 yard line). Also, if the new location will be greater or equal to 100, change the value of yards moved to the distance between this play's starting location and 100 (the end zone). For example, if the play starts at 95 and the pass play result is 20 yards, change the play result to 5 yards Also display "touchdown" and reset the location to 20 to play again. Revision 3: In the getYardsMoved method, if the result of a pass play is < 0, display the message "sacked!!" which indicates that the quarterback was tackled. if the result is 0, display the message "missed!" which indicates the ball was thrown and missed by the receiver. at location 20. pass, run, or quit (p/r/q)? a invalid entry! at location 20. pass, run, or quit (p/r/q)? o invalid entry! at location 20. pass, run, or quit (p/r/q)? p moved 5 yards. new location is 25. at location 95. pass, run 0,="" display="" the="" message="" "sacked!!"="" which="" indicates="" that="" the="" quarterback="" was="" tackled.="" if="" the="" result="" is="" 0,="" display="" the="" message="" "missed!"="" which="" indicates="" the="" ball="" was="" thrown="" and="" missed="" by="" the="" receiver.="" at="" location="" 20.="" pass,="" run,="" or="" quit="" (p/r/q)?="" a="" invalid="" entry!="" at="" location="" 20.="" pass,="" run,="" or="" quit="" (p/r/q)?="" o="" invalid="" entry!="" at="" location="" 20.="" pass,="" run,="" or="" quit="" (p/r/q)?="" p="" moved="" 5="" yards.="" new="" location="" is="" 25.="" at="" location="" 95.="" pass,="">
Oct 22, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here