Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Description: The range of integers that can be represented in Java using a primitive data type is only from 263 to 263 1. What if

Description: The range of integers that can be represented in Java using a primitive data type is only from 263 to 263 1. What if we need to manipulate integer values beyond this range? In this assignment you will write a HugeInteger class which is able to represent arbitrarily large integer numbers. This class must implement arithmetic operations on integers such as addition, subtraction, multiplication, division and comparison. You have to implement this class without using Java predened classes, unless specied otherwise. Additionally, you have to measure experimentally the running times of the operations implemented in your HugeInteger class and compare them with the measured running times of the corresponding operations provided by java.math.BigInteger class. Specifications: The class HugeInteger must contain at least the following methods: 1) public HugeInteger add(HugeInteger h): Returns a new HugeInteger representing the sum of this HugeInteger and h. 2) public HugeInteger subtract(HugeInteger h): Returns a new HugeInteger representing the dierence between this HugeInteger and h. 3) public HugeInteger multiply(HugeInteger h): Returns a new HugeInteger representing the product between this HugeInteger and h. 4) public int compareTo(HugeInteger h): Returns -1 if this HugeInteger is less than h, 1 if this HugeInteger is larger than h, and 0 if this HugeInteger is equal to h. 5) public String toString(): Returns a string representing the sequence of digits corresponding to the decimal representation of this HugeInteger. The class HugeInteger must contain at least the following constructors: 1) public HugeInteger(String val) creates a HugeIntegerfrom 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. 2) public HugeInteger(int n) creates a random HugeInteger of n digits, the rst digit being dierent from 0; n must be larger or equal to 1. Each constructor must throw an exception if the argument passed to the constructor does not comply to the specications. In your solution, you may use Java API methods for string manipulation and for pseudo-random number generation. PLEASE COMMENT IN EACH LINE ESPECIALLY THE NEGATIVE ADD, SUBTRACTION AND MULTIPLY METHODS PLEASE!!!!!

THANK YOU:)

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

From Herds To Insights Harnessing Data Analytics For Sustainable Livestock Farming

Authors: Prof Suresh Neethirajan

1st Edition

B0CFD6K6KK, 979-8857075487

More Books

Students also viewed these Databases questions