Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment, your task is to write a class in Java for big integer numbers.Normally we cannot add (or subtract etc) very big numbers,

In this assignment, your task is to write a class in Java for big integer numbers.Normally we cannot add (or subtract etc) very big numbers, say 1000 digitslong numbers. To do it, we need to store those numbers in character stringsand then add (or subtract etc) them like we did in elementary schools.Class name:BigInteger.Possible Variables:char num[1000]: a string to hold the number.int Length: length of the number.Methods:BigInteger( ): Default constructor that creates a big integer equivalent tozero.BigInteger (String num): Constructor that initializes num[ ] with thenumber given in the argument and sets the Length.BigInteger (char a[ ]): Constructor that initializes num[ ] with a[ ] andsets the Length.BigInteger (long n): Constructor that initializes num[ ] with an long valuen and sets Length. You need to convert the long n to a string in this case.voidsetBigInteger(char a[ ]): This function is like the first constructorthat initializes num[ ] with a[ ] and sets the Length.You can write more overloaded versions of setBigIntegerfunction that takes various types of arguments as the constructors does and use the set-BigIntegerfunction inside of the constructor!BigIntegeradd(BigInteger n): Adds big integer n to current object andreturns the result, without affecting the current object.BigIntegersubtract(BigInteger n): Subtracts big integer n from current object and returns the result, without affecting the current object.1BigIntegermultiply(BigInteger n): Multiplies big integer n with currentobject and returns the result, without affecting the current object.BigIntegerdivide(int n): Divides the current big integer with a non nega-tive integer n and returns the quotient, without affecting the current object.BigIntegermod(int n): Divides the current big integer with a non negativeinteger n and returns the reminder, without affecting the current object.BigIntegerincrement( ): Increments the current object and also returnsthe result. Note that, current object is modified.BigIntegerdecrement( ): Decrements the current object and also returns the result. Note that, current object is modified.void show( ): Prints the big integer on screen.Sample Code p u b l i c c l a s s B i g I n t e g e r{/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /// w r i t e y o u r c o d e h e r e ! ! ! ! !/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /p u b l i c s t a t i c v o i d main ( S t r i n g [ ] a r g s ){B i g I n t e g e r x = new B i g I n t e g e r ( " 1 2 3 4 5 " ) ;B i g I n t e g e r y = new B i g I n t e g e r ( 1 0 ) ;B i g I n t e g e r z ;z = x . add ( y ) ;z . Show ( ) ;// p r i n t s : 12 35 5z = x . s u b t r a c t ( y ) ;z . Show ( ) ;// p r i n t s : 12 33 5y . s e t B i g I n t e g e r ( " 1 0 0 " ) ;z = x . m u l t i p l y ( y ) ;z . Show ( ) ;// p r i n t s : 1 2 3 4 5 0 0z = x . d i v i d e ( 1 0 0 ) ;z . Show ( ) ;// p r i n t s : 123z = x . mod ( 1 0 ) ;z . Show ( ) ;// p r i n t s : 5x . i n c r e m e n t ( ) ;x . Show ( ) ;// p r i n t s : 1 23 46x . i e c r e m e n t ( ) ;x . show

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

Students also viewed these Programming questions

Question

=+11. Define the inflation tax. Who pays it?

Answered: 1 week ago