Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA only!!! Define and implement a class HugeInteger that represents integers of 300 digits and a few simple operations on them, as indicated below. Define

JAVA only!!!

Define and implement a class HugeInteger that represents integers of 300 digits and a few simple operations on them, as indicated below. Define a static constant hugeIntegerSize = 300. The integers are to be represented, in decimal notation, by a private data structure that consists of: ? A byte array of decimal digits 0-9, of which the position of a digit equals to the corresponding power of 10. ? The integer's sign (i.e., plus or minus?an enum type).

The following operations should be supported:

? A constructor HugeInteger(int length) for creating a Huge Integer of given length that consists of zeros.

? A constructor HugeInteger(String str) for creating a Huge Integer, given a string of its digits.

? An operation getLength() for determining the length of a Huge Integer.

? An operation byte getDigit(int index) for obtaining a digit of a Huge Integer given its index. The starting index is 0. If the index is out of bounds, then a message should be printed on the screen indicating this fact.

? An operation void print(HugeInteger i), which, if the number is negative, prints "-" followed by the number's digits. (The "+" sign is superfluous for positive numbers and meaningless for 0.) Note that the number has to be printed from right to left as the least significant digit is on the left.

? An operation String toString() for transforming a Huge Integer to a String. With that, if the number is negative, the first character in the string should be "-" . (The "+" sign is superfluous for positive numbers and meaningless for 0.) Note that the number has to be inserted into a string from right to left as its least significant digit is on the left.

? An assignment operation, void Assign(HugeInteger i), which copies the value of the operand i. (It might make sense to allow that operation to use any integer?not only a Huge Integer.

? Boolean operations for equality check as well as greaterThan and lessThan relatation. (Note that the comparison has to be performed digit-by-digit).

? Arithmetic operations Add, Subtract, and Mult. All operations have to be performed digit-by-digit, propagating the carry. In case of the overflow, you need to throw an exception. (Mult is the most complex operation, naturally, but at this point you don't have to do anything ingenious?program it in the most straight-forward way possible.)

? Start thinking about how you would implement the Integer division operation Divide. If you have time, implement it; otherwise, leave it for later. To this end, feel free to use any algorigthm that you can find on the Web, but make sure that you implement it yourself.

image text in transcribed
HugeInteger public HugeInteger(int length) public HugeInteger (String str) public int getLength() public byte getDigit(int index) public boolean equal(HugeInteger i) public boolean greaterThan(HugeInteger i) public boolean lessThan( HugeInteger i] public void assign (HugeInteger i) public void add(HugeInteger i) public void mult(HugeInteger i) public void divide (HugeInteger i) public String toString()

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_2

Step: 3

blur-text-image_3

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

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions

Question

The term up in the air means undecided.

Answered: 1 week ago