subject

Assume that the classes listed in the Java Quick Reference have been imported where appropriate. Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied.
In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit.

4. This question involves generating a String that will be used as an identifier. You will write the generateID method of the following Identifier class.

public class Identifier
{
/** Encodes a string as an integer and returns the encoded int value */
public static int encodeToNumber(String str)
{ /* implementation not shown */ }

/** Returns an identifier string based on an input string, as described in part (a)
* Precondition: input is not null.
*/
public static String generateID(String input)
{ /* to be implemented in part (a) */ }

// There may be variables and methods that are not shown.
}
(a) Write the generateID method, which is used to transform an input string into a string that can be used as an identifier. The method creates and returns the identifier string based on the following rules.

If the length of the input string is not divisible by 4 , the method returns the string "error".
Every non-overlapping 4 -character grouping of the input string is encoded as an integer using the helper method encodeToNumber. The sum of all the encoded values is calculated.
If the sum is greater than 100 , the method returns the original input string with "3" appended.
Otherwise, the method returns the original input string with "X" appended.
The following table shows some examples of calls to the generateID method. Assume that all calls occur in the Identifier class.

Call to generateID
Possible Values Returned by

encodeToNumber

generateID

Return Value

generateID("treebook")
encodeToNumber("tree")

returns 17

encodeToNumber("book")

returns 2

"treebookX"
generateID("doordesklion")
encodeToNumber("door")

returns 56

encodeToNumber("desk")

returns 35

encodeToNumber("lion")

returns 86

"doordesklion3"
generateID("today")
"error" (because

the length of

"today" is not

divisible by 4 )

Complete method generateID. You must use encodeToNumber appropriately to receive full credit.

/** Returns an identifier string based on an input string, as described in part (a)
* Precondition: input is not null.
*/
public static String generateID(String input)
listNumbered listImage (12 image limit)
Edit imageView imageDelete image
0 / 10000 Word Limit
Question 2
(b) A programmer wants to modify the Identifier class to keep track of how many times a call to generateID returns "error". The programmer would like to implement this change without making any changes to the signatures of generateID or encodeToNumber or overloading either method.

Write a description of how you would change the Identifier class in order to support this modification. Do not write the program code for this change.

Make sure to include the following in your response.

Identify any new or modified variables or methods.
Describe, for each new or revised variable or method, how it would change or be implemented, including visibility and type.

ansver
Answers: 2

Another question on Advanced Placement (AP)

question
Advanced Placement (AP), 23.06.2019 11:20
I’ll give you free brainliest + free points if you answer this correctly the most common cause of a stuck accelerator is the a. engine b. steering wheel c. brakes d. floor mat
Answers: 1
question
Advanced Placement (AP), 23.06.2019 19:30
According to the online content activity for this lesson, what should you do if you do not understand the material you are trying to learn? a. try a new approach to learning the material. c. re-read the material b. give up d. find someone to give you the answers to the test select the best answer from the choices provided a b c d
Answers: 2
question
Advanced Placement (AP), 24.06.2019 05:00
Ronan has been working as domestic at a large mansion since a few months. recently, he has taken his employer’s seven-year-old boy by force and held him captive. he has demanded money from his employer in return of the boy. which crime has ronan committed? a. treason b. sedition c. assault and battery d. kidnapping
Answers: 2
question
Advanced Placement (AP), 24.06.2019 10:00
1  2  3  4  5  6  7  8  9  10  below is a chart representing portions of rĂ©sumĂ©s from three applicants.                                      excerpts from rĂ©sumĂ©s of three job applicants  job expertise    applicant 1  developed effective techniques for keeping order in the classroom    applicant 2  effectively designed a program for new employees    applicant 3  took many courses in child psychology and human development      which  best  explains the applicants’ careers?
Answers: 3
You know the right answer?
Assume that the classes listed in the Java Quick Reference have been imported where appropriate. Un...
Questions
Questions on the website: 13722360