Write a method fixItUp that takes a string as input and returns a string with the characters put the way that they ought to have been. See the fixItUp method in the StringWorker class in the bookClassesFinal directory.

You worked late into the night on an assignment and didn’t realize that you wrote a huge section of your term paper with your fingers on the wrong home keys!
Where you mean to type: “This is an unruly mob.” You actually typed: “Ty8s 8s ah 7hr7o6 j9b.”
Basically you swapped: 7 for U, 8 for I, 9 for O, 0 for P, U for J, I for K, O for L, H for N, and J for M. (Those were the only keystrokes that you got wrong-you caught yourself before you got much further.) You also never touched the shift key, so it’s all lowercase letters that you care about.
Knowing Java as you do, you decide to write a quick program to fix your text.


```
/? ?
? Method t o f i x up bad t y p i n g on a s t r i n g
?/
public s t a t i c S t r i n g f i x I t U p ( S t r i n g badInput )
{
char [ ] charArray = new char [ badInput . l e n g t h ( ) ] ;
char currChar ;
// l o o p t h r o u g h t h e c h a r a c t e r s i n t h e s t r i n g
f o r ( i n t i = 0 ; i < badInput . l e n g t h ( ) ; i ++)
{
currChar = badInput . charAt ( i ) ;
i f ( currChar == ’ 7 ’ )
charArray [ i ] = ’ u ’ ;
e l s e i f ( currChar == ’ 8 ’ )
charArray [ i ] = ’ i ’ ;
e l s e i f ( currChar == ’ 9 ’ )
charArray [ i ] = ’ o ’ ;
e l s e i f ( currChar == ’ 0 ’ )
charArray [ i ] = ’ p ’ ;
e l s e i f ( currChar == ’ u ’ )
charArray [ i ] = ’ j ’ ;
e l s e i f ( currChar == ’ i ’ )
charArray [ i ] = ’ k ’ ;
e l s e i f ( currChar == ’ o ’ )
charArray [ i ] = ’ l ’ ;
e l s e i f ( currChar == ’ h ’ )
charArray [ i ] = ’ n ’ ;
e l s e i f ( currChar == ’ j ’ )
charArray [ i ] = ’m’ ;
e l s e i f ( currChar == ’ y ’ )
charArray [ i ] = ’ h ’ ;
e l s e i f ( currChar == ’ 6 ’ )
charArray [ i ] = ’ y ’ ;
else
charArray [ i ] = currChar ;
}
return new S t r i n g ( charArray ) ;
}

```

Computer Science & Information Technology

You might also like to view...

While you are presenting in Office Presentation Service, you can make minor edits to the document

Indicate whether the statement is true or false

Computer Science & Information Technology

A _____ graphically documents a use case by showing the classes, the messages, and the timing of the messages.

A. state transition diagram B. sequence diagram C. data flow diagram D. scatter diagram

Computer Science & Information Technology

Differentiate between the use of a function and a formula in a table. When would one be preferable to another? Provide several examples.

What will be an ideal response?

Computer Science & Information Technology

What happens in the execution of a switch statement if no case clauses are matched and there is no default clause?

What will be an ideal response?

Computer Science & Information Technology