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.
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.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 5 images
Knowledge Booster
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.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education