Answered step by step
Verified Expert Solution
Link Copied!

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 263(about 16 billion, a number with 11 digits).
But we cannot store in a single memory cell the number 323445645332329488575477890349030.
In this exercise, a class named BigNum will be built that will represent large non-negative 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 0. 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 1. For example, the number 23125 would be stored in the array like this:
23125-1-1-1-1-1
0123456789
question 1 :
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 MAX_DIGITS constant in the class to indicate the maximum number of digits that can be stored in a number. Initialize it to 50.
Added the following constructors to the class:
public BigNum() an empty constructor that will initialize the number to 0.(Note that 0 is represented by an array whose first cell has 0 and all other cells have 1-).
public BigNum(long 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 23125 represented in the array above, the toString method will return the string "23,125". 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 23125 the method will return 5.
public boolean equals(BigNum 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 add(BigNum 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 MAX_DIGITS the method will return null.
public BigNum add(int 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 1 to the number represented by this and return the result as a new object of type BigNum.
public BigNum multiply(BigNum 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 mod(BigNum 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions

Question

What is topology? Explain with examples

Answered: 1 week ago