Answered step by step
Verified Expert Solution
Question
1 Approved Answer
We know that the size of the numbers that can be stored in the computer's memory cells is limited . A memory cell of type
We know that the size of the numbers that can be stored in the computer's memory cells is limited A memory cell of type long can store an integer up to a size of about billion, a number with digits
But we cannot store in a single memory cell the number
In this exercise, a class named BigNum will be built that will represent large nonnegative numbers by an array. Each digit in the number will be stored in a cell in the array, with the leftmost digit MSB stored in cell number Since the array will be of fixed size, each cell in the array that does not contain digits from the number will contain the The number For example, the number would be stored in the array like this:
question :
Write the BigNum class in JAVA to represent a large number as described. The class will contain a single attribute:
num of type int
Define the MAXDIGITS constant in the class to indicate the maximum number of digits that can be stored in a number. Initialize it to
Added the following constructors to the class:
public BigNum an empty constructor that will initialize the number to Note that is represented by an array whose first cell has and all other cells have
public BigNumlong n the constructor will accept as a parameter a number of type long and insert its digits into the array.
Add the following methods to the class:
public String toString the method will return the number in the form of a string where a comma will appear after every three digits on the right. For example, if the number is represented in the array above, the toString method will return the string Note that if the number contains three or fewer digits, no commas will appear in the string.
public int getNumOfDigits the method will return the number of digits of the number. For example, for the number the method will return
public boolean equalsBigNum n the method will accept as a parameter an object of type BigNum and return true if this is equal to n and false if not.
public BigNum addBigNum n the method will receive as a parameter an object of type BigNum and perform a connection between n and this. The method will return the result as a new object of type BigNum. Note, if the result of the concatenation creates a number with more digits than MAXDIGITS the method will return null.
public BigNum addint n the method will accept an integer n as a parameter and connect it to the number represented by this and return the result as a new BigNum object.
public BigNum plusplus the method will add to the number represented by this and return the result as a new object of type BigNum.
public BigNum multiplyBigNum n the method will receive as a parameter an object of type BigNum and return the product of n in this. The method will return the result as a new object of type BigNum
public BigNum modBigNum n the method will receive as a parameter an object of type BigNum and return the remainder from dividing this by n as a new object of type BigNum.
JAVA PLEASE
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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