Question
Implement the Web service which represents a number guessing game. The game has the following methods: @WebMethod(operationName = startGame) public synchronized String startGame() @WebMethod(operationName =
Implement the Web service which represents a number guessing game. The game has the following methods:
@WebMethod(operationName = "startGame") public synchronized String startGame() @WebMethod(operationName = "playGame") public synchronized String playGame(@WebParam(name = "num") int num) |
When the startGame() method is called, a random integer between 0 and 100 inclusively is generated. The returned string of the method is "game started". The player has to guess the number by invoking the playGame() method. The guessed number is passed as the parameter to the method. The player has five times to make a correct guess. The returned string of the method is:
- if no correct guess has been made:
- if the number of guesses made (excluding the current one) is less than 5:
- if the guess is correct, then the returned string is: "correct", otherwise, the returned string is "should be greater" or "should be less" depending on the actual integer is greater or less than the provided guess.
- if the number of guesses made (including the current one) is greater than 5, the string returned is "You have made more than 5 guesses".
- if the number of guesses made (excluding the current one) is less than 5:
- If a correct guess has been made, then the returned string is "A correct guess has been made already".
Complete the following incomplete code for the Web service:
@WebService(serviceName = "Game") public class Game { //**** attributes in the class: .........
@WebMethod(operationName = "startGame") public synchronized String startGame() { //**** implementation of startGame() ........... }
@WebMethod(operationName = "playGame") public synchronized String playGame(@WebParam(name = "num") int num) { //***** implementation of playGame ........... }
} |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started