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 20:00
With my drivers ed and i’ll mark you brainliest + free 10 points adjusting the driver's seat is a. only necessary when you purchase a new vehicle b. usually enough to make up for an arm or leg injury c. not necessary if you're only driving a few miles d. not just for comfort
Answers: 1
question
Advanced Placement (AP), 25.06.2019 01:30
General ways to reduce the risk of some action include
Answers: 1
question
Advanced Placement (AP), 25.06.2019 21:30
If you have a green turn signal light, you must before making your turn. a. check the crosswalk b. yield to cross traffic and check the crosswalk c. turn off your car's turn signal d. none of the above
Answers: 2
question
Advanced Placement (AP), 26.06.2019 08:00
Which of the following is a downside to using a professional naming firm? question options: you'll no longer have control over your company's name. most aren't very good at coming up with effective names and logos. you will need to be cautious about the firm stealing your business idea. most are fairly expensive, charging from $5,000 to $80,000 to develop a name.
Answers: 1
You know the right answer?
Assume that the classes listed in the Java Quick Reference have been imported where appropriate. Un...
Questions