Question
This question involves generating a String based on a numeric value. You will write the buildString method of the following Converter class. public class
This question involves generating a String based on a numeric value. You will write the buildString method of the following Converter class.
public class Converter
{
/** Returns a String based on the single-digit integer num
* Precondition: num is a single-digit integer.
*/
public static String convertToString(int num)
{ /* implementation not shown */ }
/** Returns a string based on an integer input value, as described in part (a)
* Precondition: input > 0
*/
public static String buildString(int input)
{ /* to be implemented in part (a) */ }
// There may be variables and other methods that are not shown.
}
(a) The buildString method takes an integer value as input, obtains strings based on each digit of the input, and returns the concatenated strings.
A helper method, convertToString, has been provided. The convertToString method returns a string based on a single-digit integer input value. For example, the method call convertToString(7) might return the String "paper".
The strings returned by convertToString should appear in the String returned by buildString in the same order that the digits appeared in the original input value.
For example, assume that the following calls to convertToString are made from within the Converter class and that convertToString(1) returns "apple", convertToString(2) returns "orange", and convertToString(3) returns "banana".
Then the method call Converter.buildString(3) should return "banana", the method call Converter.buildString(123) should return "appleorangebanana", and the method call Converter.buildString(321) should return "bananaorangeapple".
Complete method buildString. You must use convertToString appropriately to receive full credit.
/** Returns a string based on an integer input value, as described in part (a)
* Precondition: input > 0
*/
public static String buildString(int input)
Step by Step Solution
3.48 Rating (151 Votes )
There are 3 Steps involved in it
Step: 1
public static String buildStringint input Base case if input is a single dig...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started