Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A lottery company sells scratch cards.In addition to the game itself, each card has a verification code.When a user wishes to claim a win, they

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

You are to write the verification method that 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 Stringand the secretKey as a String.The prizes available are 1, 3 and 5.The method 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 make) 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 the position to start from 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 at least as long as 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)

{

//make and initialise the prize variable to zero here

// insert your loop here

// and return your value here

}

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

=+ c. What happened to the velocity of money over this time period?

Answered: 1 week ago