Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The code should just be within the findNumber method. Make sure it meets the requirements. 6 Guesser.java o 633 Bytes 1 2 import java.math.BigInteger; 3

The code should just be within the findNumber method. Make sure it meets the requirements.

image text in transcribedimage text in transcribed

6 Guesser.java o 633 Bytes 1 2 import java.math.BigInteger; 3 public class Guesser { 4 5 * This method must return the number Chooser c has chosen. c can guess() any * number and tell you whether the number is "correct", "higher", or "lower", 6 7 8 9 19 11 * @param c The "chooser" that has chosen a number you must guess. * @return The number that the "chooser" has chosen * public static BigInteger findNumber(Chooser c) { // Tip: If you're not sure how to work with BigInteger numbers, we encourage // you to look up its Javadoc online. throw new RuntimeException("Remove this line and implement me!"); } 12 13 14 15 16 } Chooser.java o 571 Bytes 1 import java.math.BigInteger; 2 3 4 5 6 /** * A Chooser will pre-emptively choose a number that a Guesser must guess. */ public interface Chooser { /** * You can use this method to guess any number and the chooser will return * a String on whether the number numToGuess is "correct", "higher", or "lower" 7 8 9 10 11 12 13 14 * @param numToGuess An arbitrary number to guess. * @return "correct" (your answer is correct), * "higher" (the correct answer is higher), * or "lower" (the correct answer lower) */ String guess (BigInteger numToGuess); 15 16 17 } "Guessing Game" is a game with two parties: the "chooser" and the "guesser". The "chooser" picks a natural number larger than zero, and the "guesser" must guess what it is. The "guesser" repeatedly makes guesses to the "chooser" until the correct answer is found. Note that there is no upper bound on the number the "chooser" can pick. Tasks Set Up Before you begin, take a look at the Setting Up Your CSE 332 Environment handout. This will prepare your development environment for both this assignment and future programming projects. After you have IntelliJ and Git set up, follow the instructions on that document to clone this repository. Completing the Exercise Write Java code for findNumber(), a method that simulates the "guesser" in a guessing game by making a series of guesses and returning the correct answer. You should not have to bruteforce the number one-by-one. If the number chosen is n > 2, your code may make at most 2 log2(n) guesses. Open src/main/java/Guesser.java to get started. It might also be helpful to take a look at the Chooser.java interface; however, you should only edit the method findNumber in Guesser.java

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions