Write a program that plays a guessing game with the user. Specifically, your program should randomly pick a number between 1 and 100. Then, ask the user for a guess. You should detect and tell the...

Write a program that plays a guessing game with the user. Specifically, your program should randomly pick a number between 1 and 100. Then, ask the user for a guess. You should detect and tell the user if the guess is not a valid guess. Otherwise, tell the user their guess was too high or too low. The program should continue to prompt the user for new guesses until they get the correct number, telling them each time if the guess was too high or too low or invalid. Here are a couple development/debugging strategies for this “target” variable: •Print out the random number, to make sure your program is acting correctly– remember to remove/comment this before running unit tests/submitting. •Temporarily set the random “seed” to a value, which will have the effect of always choosing the same random number–the unit tests have fixed seeds that you can use with known outcomes. •Temporarily set the “target” variable to a fixed number, so you can test to see how your program responds in different testing situations. Base code: package edu.wit.cs.comp1000; import java.util.Random; //TODO: document this class public class PA4b { // TODO: document this method public static void main(String[] args) { ////////////////////////////////////////////////////////////////////////////// // DO NOT CHANGE IN FINAL SUBMISSION ////////////////////////////////////////////////////////////////////////////// Long seed; if (args.length != 1) { seed = null; // you can temporarily change this to assist in debugging // the value must end in L, such as 1070L } else { seed = Long.valueOf(args[0]); } // Gets a random number between 1 and 100 // Use the target variable as the correct answer for guessing Random random; if (seed == null) { random = new Random(); } else { random = new Random(seed); } int target = (Math.abs(random.nextInt()) % 100) + 1; ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // It might be useful to see the correct answer // TODO: delete this line before attempting unit tests or submitting work System.out.println(target); // TODO: write your code here } }
Nov 20, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here