help me to finish those 2 question int[] data = {}; //data array store digits in this natural number /** * THIS IS A HELPER
help me to finish those 2 question
int[] data = {}; //data array store digits in this natural number
/**
* THIS IS A HELPER method which converses a digit character to its integer value.
* @param c is character and assumed be one of the following '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
* @return an integer value of character in c
*/
private int toInt(char c)
{
return (int)c - (int)'0';
}
/**
* A parameterized constructor
* @param initData is a String containing the digits of this NaturalNumber
* instantiate the data array to correct size and store the digits from initData
* as an integer in array data.
*
* The constructor should use its setter to set each digit to
*/
public NaturalNumber(String initData)
{
// write code
return;
}
/**
* A setter : setting an integer between 0 to 9 to a digit specified by parameter digitIndex to the data array
* @param digitIndex is the index to data array
* @param value is an integer between 0 and 9
*
* setter validation:
* @param digitIndex must be between 0 and data.length - 1 AND @param value must be between 0 and 9
* otherwise, this setter should not do anything to the data array.
*/
public void setDigit(int digitIndex, int value)
{
//write code
return;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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