Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

UTSA Computer Science DepartmentCS3443: Application ProgrammingLab 2Lab SummaryFamiliarity with Eclipse IDE.Java syntax.Object oriented programming.DescriptionIn this assignment, your task is to w in Java for big

UTSA Computer Science DepartmentCS3443: Application ProgrammingLab 2Lab SummaryFamiliarity with Eclipse IDE.Java syntax.Object oriented programming.DescriptionIn this assignment, your task is to w in Java for big integer numbers.Normally we cannot add (or subtract etc) verybig 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 ofsetBigIntegerfunction thattakes various types of arguments as the constructors does and use theset-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 currentobject 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 returnsthe result. Note that, current object is modified.void show( ): Prints the big integer on screen.Sample Codep 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 ( ) ;// p r i n t s : 12 3 45}}2Assume that no intermediate result will exceed 1000 characters.Assume that all the numbers, including results, will be non negative.You can add other methods or variables for your own use.Easiest way to test your program is to use the Valladolid online judge(http://acm.uva.es/problemset). You can solve some straight forward biginteger related problems (e.g. problem number 623, 10106, 10579 etc) fromthis site using your class to test its efficiency.3

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions