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)
BoldItalicUnderlineBullet 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.

Answers

Answer 1

Answer: To modify the Identifier class to keep track of how many times generateID returns "error", a new variable, say errorCount, can be added to the class as a private static integer variable to store the count. This variable can be initialized to 0 in the class constructor.

Next, in the generateID method, before returning "error", increment errorCount by 1. This would keep track of the number of times "error" is returned by the generateID method.

Finally, a new method, say getErrorCount, can be added to the class to return the errorCount value. This method can be a public static method that simply returns the errorCount value.

This way, the programmer can track the number of times generateID returns "error" without making any changes to the signatures of generateID or encodeToNumber or overloading either method.


Related Questions

What is the difference between unconfined aquifers and confined aquifers?

Answers

Answer:

A confined aquifer is an aquifer below the land surface that is saturated with water. ... A water-table--or unconfined--aquifer is an aquifer whose upper water surface (water table) is at atmospheric pressure, and thus is able to rise and fall.

Help me ASAP please frist one will get brainlist If

Answers

Answer:

42 inches

Explanation:

♪\(*^▽^*)/\(*^▽^*)/

Answer:

Hey

Explanation:

What are some common work contexts for psychiatrists

Answers

Answer:

Prescribe medications.

Prescribe treatments or therapies.

Treat patients using psychological therapies.

Collect medical information from patients, family members, or other medical professionals.

Record patient medical histories.

Develop medical treatment plans.

Explanation:

i,ll mark you the brainlyest, What is the difference between oxygen gas and ozone gas?

*Oxygen gas is not necessary for animals to exist, ozone is important to breathing.

*There is no difference between oxygen gas and ozone; they are the same thing.

*Oxygen gas contains two atoms of oxygen, ozone contains three atoms. Ozone gas is found in small amounts in the atmosphere.

*Ozone gas is found only in the upper atmosphere; oxygen gas is found very close to Earth's surface.

Answers

Answer: Ozone is an alternative version of oxygen. Oxygen or (O2) in the air we breathe is actually two molecules of oxygen attached together. Ozone is three atoms of oxygen attached together forming a molecule that is O3.

HURRY 10 POINTS
Which of the following is an example of TCP/IP use?


sending a package through UPS or FedEx

calling a florist and scheduling a delivery

mailing a letter through the post office

scanning a signed contract and uploading it to a real estate agency

Answers

Answer:

mailing a letter through the post office

scanning a signed contract and uploading it to a real estate agency

Answer:

mailing a letter through the post office

Other Questions
Part A Which statement best captures the central message of Silvers interview with Rebecca Skloot? a. Skloots accusations of racism center around the scientists lack of compassion in dealing with Henrietta Lacks children. b. The Lacks familys privacy rights had been violated for years as information about Henrietta Lacks's tissue samples were released to the public without permission. c. Skloot is optimistic the Lacks descendants will move into the future understanding how Henrietta Lacks helped the world. d. The Lacks family's recent involvement in HeLa research is a positive move forward because it signals a more open, ethical dialogue between the public community and the scientific community. What's the definition of repel in biology ? its cShe wants to display casts of soldiers remains in a museum.got it right on my unit test for edge 2021 Did you hear about the two punsters who told a lot of jokes !!!!Someone help me with this!!!!!!Eukaryotic Cell Structure and Function !!!!(Will Give Brainliest Answer)!!! Who ever gets this one Ill mark them Help needed very much The table shows the number of words Marla can type in a given time.Time(minutes)Number ofWords5 | 14010 | 28015 | 42020 | 60What is Maria's typing rate?A. 21 words per minuteB. 28 words per minuteC. 84 words per minuteO D. 140 words per minute What is the perimeter of this figure? Help? I need these completed If you were on the moon, your welght would only be 0.17 of your welght on Earth. If you weigh 195.75pounds on Earth, how much would youweigh on the moon?You would weigh [blank]pounds on the moon if you weigh 195.75 pounds on Earth. please help ill mark you brainliest! an ionic bond forms between a ______ and a _____ Do you think the media or public judged OJ Simpson before the jury did? 18a 17a = 13 I Will give You Brainly. (: Find the solution to the system. Write your solution as an ordered pair (x,y)with no spaces, no solution, or infinitely many. 2x+6y=56 and 4x+12y=24 * How can x minus two-thirds = StartFraction 5 over 6 EndFraction be solved for x in one step? 1. In sentence 5 (reproduced below), the writer wants to use a transitional phrase to show the relationship between the evidence in the sentence and the other ideas in the paragraph. Which version of the capitalized text best achieves this goal? SUBSEQUENTLY, humans typically pass the test starting at around 18 months of age GIVING BRAINLIEST, FIVE STARS AND THANKS!!!!!!!!!!!!!!!!!!!!!!!!!!!:)What are the advantages of using nuclear energy instead of oil and coal to produce energy? Which sentence is correctly punctuated? Select one:a.We must all live together; we must all be concerned about each other.b.We must all live together, we must all be concerned about each other.