Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java, Android Studio. For this assignment you are to create an Android app that will implement the (in)famous game of LaurieMOO! The game is simple:

Java, Android Studio.

For this assignment you are to create an Android app that will implement the (in)famous game of LaurieMOO! The game is simple: you have ten attempts to guess a four-digit number randomly generated by the game. For each digit correctly specified by position, you get a MOO! displayed by the program. For each digit specified that is not in the correct position but is in the solution, a moo. is displayed. You are NOT required to indicate the location of the correct digits through the MOO! or moo. items displayed by your program. If the number is correctly guessed, then in addition to all four MOO! strings being displayed you also get a LaurieMOO!!! as a reward. If the user fails to guess the number after ten attempts, the message Boo hoo -- no LaurieMOO. is displayed along with the four-digit number (so that the user knows what the answer was).

Feel free to be creative with the GUI for this program; if adventurous, try to incorporate sound and/or pictures. At a minimum, there should be a text view for user input, at least one text view for displaying text output, and a button to guess. Note that it is acceptable to build a string such as MOO! moo. moo. and display that string on one text view. Please note that the number generated by the program can be any four-digit number: it can have leading zeros, it can have multiple instances of the same digit, and so on. For example, the following secret values are all possible: 0000, 0123, 3455, 7870.

You are to use appropriate OOP-design principles for this assignment by creating the RandomMooValue class. An instantiation of this class will create a guessable 4-digit value as an instance variable. You must, at a minimum, implement the constructor and methods as indicated by the Javadoc for this class provided at the end of this assignment.

Class RandomMooValue

Creates a 4-digit secret value (0000 through 9999) for a player to guess. Feedback is returned in the form of big and little moos. Each "MOO!" indicates a character/digit correctly guessed in both value and position. Each "moo." indicates a character/digit correctly guessed in terms of value, but not position. If no characters/digits are correctly guessed, then all the user hears are cowbells... Please note that the number generated by the program can be any four-digit number: it can have leading zeros, it can have multiple instances of the same digit, and so on. For example, the following values are all possible: 0000, 0123, 3455, 7870. When generating big (MOO!) and little (moo.) moos, each guessed character/digit can only match at most one character/digit in the secret value. For example, if the secret value is 0055 and the user's guess is 5550, our favorite cow should be uttering "MOO! moo. moo." as there is an exact match in digit position 3, plus two inexact matches. Please note we are storing the 4-digit number as a String data type.

Constructor Summary

Constructor and Description

RandomMooValue()

Creates a new RandomMooValue object containing a secret value to be guessed.

Method Summary

Modifier and Type

Method and Description

int

getBigMooCount(String guess)

The number of digits in the user's guess that exactly (i.e., same position) matches digits in the secret value.

int

getLittleMooCount(String guess)

The number of digits in the user's guess that match digits in the secret value, but are not at the same position.

String

getSecretValue()

Access the value that the user is trying to guess.

boolean

isCorrectGuess(String guess)

Determines if the user correctly guessed the secret value .

boolean

setSecretValue()

Generates a new secret value to be guessed in a game of LaurieMOO.

boolean

setSecretValue(String n)

Sets the "secret" value to be guessed in a game of LaurieMOO to a known 4-digit quantity.

Constructor Detail

RandomMooValue

public RandomMooValue()

Defacult Constructor. Creates a new RandomMooValue object containing a secret value to be guessed.

Method Detail

setSecretValue

public boolean setSecretValue()

Generates a new secret value to be guessed in a game of LaurieMOO.

Returns:

true in all cases.

setSecretValue

public boolean setSecretValue(String n)

Sets the "secret" value to be guessed in a game of LaurieMOO to a known 4-digit quantity in the form of a String. This method is for testing purposes only. (HINT: if the user only types 55 you will need to add the 2 leading 0s. HINT 2: if the length is 4 and everything is a digit your value is within the correct range)

Parameters:

n - The number that will be set as the secret value, if it is within the inclusive range of 0000-9999.

Returns:

true if the secret value was reset; false if the passed value was outside of the allowed range of values.

getSecretValue

public String getSecretValue()

Access the secret value that the user is trying to guess, primarily to show the user after running out of guesses.

Returns:

the secret value that the user is/was attempting to guess.

getBigMooCount

public int getBigMooCount(String guess)

The number of digits in the user's guess that exactly (i.e., same position) matches digits in the secret value.

Parameters:

guess - The number that the user guessed in String format.

Returns:

a number 0-4 representing how many digits the user guessed correctly by position.

getLittleMooCount

public int getLittleMooCount(String guess)

The number of digits in the user's guess that match digits in the secret value, but are not at the same position.

Parameters:

guess - The number that the user guessed in String format.

Returns:

a number 0-4 representing how many of the guessed digits match, but are in different positions. Note that a guessed number cannot have any one digit generate both a "MOO!" and a "moo." as a result.

isCorrectGuess

public boolean isCorrectGuess(String guess)

Determines if the user correctly guessed the secret value.

Parameters:

guess - The number that the user guessed in String format.

Returns:

true if the guess is correct, false otherwise.

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: 3

blur-text-image

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

Databases Demystified

Authors: Andrew Oppel

1st Edition

0072253649, 9780072253641

More Books

Students also viewed these Databases questions