Question

In: Computer Science

A lottery company sells scratch cards. In addition to the game itself, each contains a verification...

A lottery company sells scratch cards. In addition to the game itself, each contains a verification code. When a user wishes to claim a win, they enter the value they are claiming and the verification code into the system. The system then uses a secret key to determine the validity of the claim.

You are to write the verification method which will be passed the data entered by the claimant together with the secret key.

The verification method verifyWin takes three arguments, the claimValue in pounds as an int, the verificationCode from the card as a String and the secretKey as a String. The prizes available are £1, £3 and £5. It returns a Boolean value, true if the claim is valid, false if not.

To determine whether a verificationCode is valid, it is compared to the secretKey character by character.

A local variable prize (which you must create) is initially set to 0 and will represent the prize value in the verificationCode once the processing has completed.

Next an appropriate loop is entered to compare the characters in the verificationCode and the secretKey, one at a time in the order left to right.

Each time the code in the body of the loop executes, it examines the next pair of characters. If the characters at the current position match, the numerical position of the match is added to the prize. If they do not match, the numerical position is subtracted. (We take position to start at 1, whereas strings are indexed from 0.)

When all of the characters have been compared the value in prize contains the value of a valid claim for this card. It is compared to the claimValue to determine if the claim is valid. If they match, return true. If not return false.

The keys may be different lengths, but the secretKey will always be shorter than the verificationCode. Compare only as many positions as the shorter string

You will need the charAt() method to access the correct character.

You should assume that the inputs are always valid.

*********************************************************************************

/**
*Takes three arguments:-
* claimValue - an int value representing the value claimed by the user in pounds
* verificationCode - A String representing the verification code printed on the card
* secretKey - a String representing the secret key used to validate the claim
*
* Iterates over the characters in the Strings adding the position of matches
* and subtracting the position of mis-matches to determine the prize value
* The claim is valid if the amount claimed is equal to the prize value determined.
* Returns a boolean value true if the claim is valid and false otherwise.
*/
public Boolean verifyWin(int claimValue, String verificationCode, String secretKey)
{
//create and initialise your local variable prize here
  
// insert your loop here

// and return your value here
}

Solutions

Expert Solution

Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.  If you are satisfied with the solution, please rate the answer. Let me know for any help with any other questions. Thank You ! ======================================================================

public boolean verifyWin(int claimValue, String verificationCode, String secretKey) {
//create and initialise your local variable prize here
int prize = 0;
// insert your loop here
for (int i = 0; i < secretKey.length(); i++) {
if (verificationCode.charAt(i) == secretKey.charAt(i)) {
prize += i + 1;
} else {
prize -= (i + 1);
}
}


// and return your value here
return prize == claimValue;
}
}

===================================================================


Related Solutions

Reference text for questions 1a-1d: Suppose a scratch-off lottery game in NC claims that their cards...
Reference text for questions 1a-1d: Suppose a scratch-off lottery game in NC claims that their cards yield an average prize of $1. To test whether the population mean prize (denote \mu ) is different from 0.25, you obtain a random sample of 81 cards. Then, you find that the mean prize in your sample (denote \overline{x} ) is equal to $0.95, and the sample standard deviation (denote s) is equal to $0.12. 1a. Which (if any) of the following options...
Java: Simple 21 Game (Blackjack) In this game, the dealer deals two "cards" to each player,...
Java: Simple 21 Game (Blackjack) In this game, the dealer deals two "cards" to each player, one hidden, so that only the player who gets it knows what it is, and one face up, so that everyone can see it. There are four players: one human player (user) and three computer players. The players take turns requesting cards, trying to get as close to 21 as possible, but not going over 21. A player may pass. Once a player has...
A company that sells baseball cards claims that 40% of the cards are rookies, 50% are...
A company that sells baseball cards claims that 40% of the cards are rookies, 50% are veterans, and 10% are all stars. Suppose a random sample of 100 cards has 55 rookies, 40 veterans, and 5 all-stars. Card Type Observed Frequency O Expected Frequency E O-E (O-E)2 (O-E)2 E Rookie Veteran All-Star Test the company's claim using a 0.01 level of significance. You may use the empty columns of the table above to assist you. a) State the null and...
A game comes with a deck of cards with each card showing one of the numbers...
A game comes with a deck of cards with each card showing one of the numbers 2, 3, 4, 5, 6, or 8. Each card occurs one time in red, one time in purple, and one time in blue. Given that a blue card is drawn, what is the probability the card is a 4?
In a particular card​ game, each player begins with a hand of 3 ​cards, and then...
In a particular card​ game, each player begins with a hand of 3 ​cards, and then draws 6 more. Calculate the probability that the hand will contain one pair​ (2 cards of one​ value, with the other cards of 7 different​ values).
1- Exchange of goods and services? 2- telcommunication company selling talk time through scratch cards? detaild...
1- Exchange of goods and services? 2- telcommunication company selling talk time through scratch cards? detaild explination at least 5 lines + the example 3- magazine subscription? detaild explination at least 5 lines + the example 4- goods sold under " Sale or Return "? detaild explination at least 5 lines + the example 5- revenue recognition for MEDIA COMPANY when the advertisment are aired even if the payment is not recevied or reveived in advance? detaild explination at least...
e5A. Boulware Company manufactures and sells electronic games. Each game costs $25 to produce, sells for...
e5A. Boulware Company manufactures and sells electronic games. Each game costs $25 to produce, sells for $45, and carries a warranty that provides for free replacement if it fails during the two years following the sale. In the past, 7 percent of the games sold had to be replaced under the warranty. During July, Boulware sold 13,000 games, and 1,400 games were replaced under the warranty. 1. Prepare a journal entry to record the estimated liability for product warranties during...
A poker hand contains five cards. Find the mean of each of the following: a. The...
A poker hand contains five cards. Find the mean of each of the following: a. The number of spades in a poker hand. b. The number of different suits in a poker hands c. The number of aces in a poker hand. d. The number of different face values in a poker hand. Show steps for each part please.
On October 1, 2021, a company sells $800 of gift cards to customers. The gift cards...
On October 1, 2021, a company sells $800 of gift cards to customers. The gift cards expire one year from the date of sale. By October 1, 2022, $750 of the gift cards have been redeemed and the sales recorded at the time of redemption. What entry, if any, should the company record on October 1, 2022? A) Debit Sales Revenue, $50; credit Cash, $50. B) Debit Cash, $750; credit Sales Revenue, $750. C) Debit Deferred Revenue, $50; credit Sales...
OK Corporation sells gift cards in various denominations. The company likes to sell these cards because...
OK Corporation sells gift cards in various denominations. The company likes to sell these cards because cash is collected immediately, but a certain percentage will never be redeemed for merchandise. On December 1, Year One, OK reported a balance in unearned revenue of $728,000 from the sale of gift cards. a. During December, OK sold an additional $578,000 in gift cards. Prepare this journal entry. b. During December, gift cards totaling $327,000 were redeemed to purchase inventory that had originally...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT