subtractBigInteger () – When an integer has more than a certain number of digits, it is represented using scientific notation. The int type itself cannot be used to store numbers with more than 10 digits. In some cases, this may be inconvenient as people usually expect complete numbers and doing big integer computations are inevitable. This method takes two numbers as CharStacks num1 and num2, and subtract the number stored in num2 from the one stored in numl, i.e., num1 - num2. To simply implementation, you can assume that the number stored in numl is no less than the number stored in num2. For example, when subtracting 181,749 from 314,739,847, the two stacks and the result stack would look like the following: ירי '3' low digit high digit '4' '1' '8' '4' '9' '9' '5' '3' '4' '5' ירי ירי '8' '4' '1' 'O' '1' high digit '8' '9' low digit '3' '1' '8' numl num2 stackResult In this method, you are provided with a char stack, stackResult. You will need to perform subtractions between the two operands and save the result on the result stack. Pay attention to the order of the digits (see above figure for reference). You shd t compute the subtraction between the two big numbers digit by digit (from low to high). Be sure to take care of borrows. Do not create any arrays or import the java.math.BigInteger library or anything from the Character, Integer, Double, and string classes in your implementation! You are only supposed to deal with the digits at the char and int level and make use of stacks.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 2CP
icon
Related questions
Question

 

 

 

Needed:

This method subtracts num2 from num1 (both represented as CharStacks), and saves the result on a stack.
    // Do not create any arrays! Do not use any Java libraries to do the calculation.
    // Doing so will result in points deduction.
    public String subtractBigInteger(CharStack num1, CharStack num2)
    {
        CharStack stackResult = new CharStack(64);  // stack used to store the result of the multiplication
        char borrow = 0;
       
        // TODO: complete this method
       
      
        return stackResult.toString();  // return a string representation of the stack
    }

subtractBigInteger () – When an integer has more than a certain number of digits, it is
represented using scientific notation. The int type itself cannot be used to store
numbers with more than 10 digits. In some cases, this may be inconvenient as people
usually expect complete numbers and doing big integer computations are inevitable.
This method takes two numbers as Charstacks numl and num2, and subtract the
number stored in num2 from the one stored in numl, i.e., num1 - num2. To simply
implementation, you can assume that the number stored in numl is no less than the
number stored in num2. For example, when subtracting 181,749 from 314,739,847, the
two stacks and the result stack would look like the following:
'7'
'3'
low digit
high digit
'4'
'1'
'8'
'4'
'9'
'9'
'5'
'3'
'4'
'5'
יךי
'7'
'8'
'4'
'
'O'
'1'
high digit
'8'
'9'
low digit
'3'
'1'
'8'
numl
num2
stackResult
In this method, you are provided with a char stack, stackResult. You will need to
perform subtractions between the two operands and save the result on the result stack.
Pay attention to the order of the digits (see above figure for reference). You shoud t
compute the subtraction between the two big numbers digit by digit (from low to high).
Be sure to take care of borrows. Do not create any arrays or import the
java.math.BigInteger library or anything from the Character, Integer,
Double, and String classes in your implementation! You are only supposed to
deal with the digits at the char and int level and make use of stacks.
Transcribed Image Text:subtractBigInteger () – When an integer has more than a certain number of digits, it is represented using scientific notation. The int type itself cannot be used to store numbers with more than 10 digits. In some cases, this may be inconvenient as people usually expect complete numbers and doing big integer computations are inevitable. This method takes two numbers as Charstacks numl and num2, and subtract the number stored in num2 from the one stored in numl, i.e., num1 - num2. To simply implementation, you can assume that the number stored in numl is no less than the number stored in num2. For example, when subtracting 181,749 from 314,739,847, the two stacks and the result stack would look like the following: '7' '3' low digit high digit '4' '1' '8' '4' '9' '9' '5' '3' '4' '5' יךי '7' '8' '4' ' 'O' '1' high digit '8' '9' low digit '3' '1' '8' numl num2 stackResult In this method, you are provided with a char stack, stackResult. You will need to perform subtractions between the two operands and save the result on the result stack. Pay attention to the order of the digits (see above figure for reference). You shoud t compute the subtraction between the two big numbers digit by digit (from low to high). Be sure to take care of borrows. Do not create any arrays or import the java.math.BigInteger library or anything from the Character, Integer, Double, and String classes in your implementation! You are only supposed to deal with the digits at the char and int level and make use of stacks.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 5 images

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT