Question
The range of integers that can be represented in Java using a primitive data type is only from -2^63 to (2^63)-1. Write a class called
The range of integers that can be represented in Java using a primitive data type is only from -2^63 to (2^63)-1. Write a class called HugeInteger which is able to represent arbitrarily large integer values. You have to implment this class without using Java predefined classes unless specified otherwise.
The class HugeInteger must contain the following method:
public HugeInteger add(HugeInteger h): Returns a new HugeInteger representing the sum of this HugeInteger and h.
The class HugeInteger must contain the following constructors:
public HugeInteger(String val) creates a HugeInteger from the decimal String representation val. The string contains an optional minus sign at the beginning followed by one or more decimal digits. No other characters are allowed in the string.
public HugeInteger(int n) creates a random HugeInteger of n digits, the first digit being different from 0; n has to be larger or equal to 1.
Each constructor must throw an exception if the argument passed to the constructor does not comply to the specifications. You may use Java API methods for string manipulation and for pseudo-random number generation.
Please clearly comment and explain the code.
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