Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have been working on this problem (the prompt below) but I cannot seem to get the Get Response method to work correctly. package edu.wit.cs.comp1050;

I have been working on this problem (the prompt below) but I cannot seem to get the "Get Response" method to work correctly.

image text in transcribed

image text in transcribed

package edu.wit.cs.comp1050;

import java.util.Scanner;

public class LA2a { /** * Number of digits in a valid value sequence */ public static final int SEQ_DIGITS = 10; /** * Error for an invalid sequence * (not correct number of characters * or not made only of digits) */ public static final String ERR_SEQ = "Invalid sequence"; /** * Error for an invalid pin * (not made entirely of * uppercase letters) */ public static final String ERR_PIN = "Invalid PIN"; /** * Converts an uppercase letter * to the corresponding number on * a standard phone... * * 1: * 2: ABC * 3: DEF * * 4: GHI * 5: JKL * 6: MNO * * 7: PQRS * 8: TUV * 9: WXYZ * * *: * 0: + * #: * * @param c assumed to be uppercase letter * @return corresponding phone number */ public static int letterToPhone(char c) { String[] keys = {"", "ABC", "DEF", "GHI", "JKL", "MNO", "PQRS", "TUV", "WXYZ"}; for(int i = 0; i '9') return false; } return true; } /** * Returns true if all the characters * in the input string are 'A' through 'Z' * * @param s input string * @return true if all characters are uppercase letters */ public static boolean allUppercaseLetters(String s) { for(int i = 0; i 'Z') return false; } return true; } /** * Converts a string of digits to an * array of integers (e.g. "12" -> {1, 2}) * * Assumes string is comprised of only digits! * * @param s digit string * @return corresponding integer array */ public static int[] digitStringToIntArray(String s) { int[] arr = new int[s.length()]; for(int i = 0; i Problem a (LA2a.java) In this assignment you are to implement a challenge-response system to protect a user's numeric PIN which they will enter via a phone. First you will be supplied a 1o-digit numeric string (the challenge) Then, a PIN will be supplied as though typed into a phone 2 A B C DEF GHI J KL M NO PQRS TUV WXYZ So, "AGOT" would signify PIN 2468. To compute a response, substitute each PIN digit with the corresponding challenge digit. For example, assume this challenge (indexes shown for convenience) SEQUENCE 3 INDEX 2 2 2 0 2 8 If supplied GOT' via phone (PIN: 2468), you would respond 3121 (the value at index 2, followed by index 4,...). Note that the PIN can be any length (1 or more characters). Also note that if the challenge has repeated digits, the PIN itself is protected because many input PINs could have the same response (and future communications can use a different challenge) You will need to validate the challenge (10 all-digit characters) and the PIN (all digits) and then output the response. For example: Enter value sequence: 12345 Enter PIN: HELLO Invalid sequence Enter value sequence: 0.12345678 Enter PIN: HELLO Invalid sequence Enter value sequence: 0123456789 Enter PIN: Hello Invalid PIN Enter value sequence: 0123456789 Enter PIN: HELLO Response: 43556 Enter value sequence: 3231132213 Enter PIN: AGOT Response: 3121 To build up to this capability, you will have to implement several methods, each with their own tests. It is recommended that you first implement the following method: letterToPhone converts letters to numbers via the phone keypad and then proceed to getResponse computes the response given challenge & PIN followed by these helpers stringIsKDigits helps validate the challenge (is a string a specified length?) . . alDigits helps validate the challenge (is a string all digits?) . allUppercaseLettecs helps validate the PIN (is a string all uppercase letters?) . digitStringToIntArray helps access challenge digits via index in an array and then finally implement the main method to complete the program. Bonus While not required, there are two optional methods, each with their own tests, that can earn you extra points. The goal is to compute, for a given challenge, how many PINs would produce the same response. For example, given the challenge on page 1, 3121 could have been produced by 108 PINs (3 occurs four times in the challenge, 1 occurs three times, 2 occurs three times: 4x3x3 x3-108) santValuefinds how many times a digit s found within an array (i.e. the challenge) numPossible multiplies the counts from a full response

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

Students also viewed these Databases questions

Question

23. What are the effects of cannabinoids on neuronspg99

Answered: 1 week ago

Question

What are the challenges associated with tunneling in urban areas?

Answered: 1 week ago

Question

What are the main differences between rigid and flexible pavements?

Answered: 1 week ago

Question

What is the purpose of a retaining wall, and how is it designed?

Answered: 1 week ago

Question

How do you determine the load-bearing capacity of a soil?

Answered: 1 week ago

Question

what is Edward Lemieux effect / Anomeric effect ?

Answered: 1 week ago

Question

I am paid fairly for the work I do.

Answered: 1 week ago

Question

I receive the training I need to do my job well.

Answered: 1 week ago