Question: Hope someone could help me out...Thank you Constructors initialize the private data at the point of declaration. The constructor has a String argument. Java code

Hope someone could help me out...Thank you

Hope someone could help me out...Thank you Constructors initialize the private data

Constructors initialize the private data at the point of declaration. The constructor has a String argument. Java code must analyze this string and if it correctly represents a BigInt convert the characters to integers and store them in an ArrayList or an array. Example strings your constructor must correctly deal with are: " 100", "-5", "-0", "+0","+""56DDD?" The last two examples do not rep resent an integer and must be rejected. A BigInt consists of a boolean sign and the array or Array List holding the absolute value of the number. If an array is used a third variable holding the size of the BigInt must also be included. There should be no other instance variables. The algorithm could be: Read a String if the string has a - or + as the first character remove it and set the sign. (The String substring() method can do this. If this is the only character in the string end the program.) Use a for loop to work through the string from the end of the string to the front. Store the string characters as integers. The Character wrapper class can make this conversion or the character can be cast as an integer remembering to subtract 43 from the ASCII value. If a character other than a digit is encountered end the program. With the string "549" the 9 can be placed into location 0, the 4 in location 1 and the 5 in location 2. With an Array List this happens automatically with the add method BigInt. add(index).(See Array List documentation. I wi11 put some on b1ackboard.) The toString() method creates and returns a String with the sign if it is negative and then adding the Array List integers starting from the back of the list to the front. I used a private helper method to test for the sign in the string input, set the sign and to make sure the sign was not the only character in the input string. You might consider doing this yourself. You must be familiar with the String methods to turn a string into integers that can be stored in an array. You then need to take the integers stored in an array and turn them back into a string in the toString() method. important reminders: String num = "-1234";//creates a string of 5 characters int i = num.length();//strings know their length. i has a value of 5 the string method charAt returns the character value at the specified location if(num.charAt(0) == '+'|| num.charAt(O) == '-') sub string(start) returns a new string having the same characters as the sub string that begins at index start o f this string through to the end o f the string. Index numbers begin at 0. Example: num = num. sub string(1) will as sign the string 12 3 4 to num Other String operations may be useful

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!