Professional Documents
Culture Documents
Lab Assignment 3 2020 - 2021 Fall, CMPE 211 Fundamentals of Programming II
Lab Assignment 3 2020 - 2021 Fall, CMPE 211 Fundamentals of Programming II
Lab Assignment 3
2020 – 2021 Fall, CMPE 211 Fundamentals of Programming II
In Java, integers have a range between the minimum value of -2,147,483,648 and the
maximum value of 2,147,483,647. It is a fairly large range, yet it is possible that you may
have to work with even larger numbers.
In this lab, our aim is to write a Java program that can carry out arithmetic
operations with support of large numbers in mind using custom made classes.
• BigNumber. Will be used to denote and store numbers that can be very large.
1
Computer Engineering Department
BigNumber Class
Data Declarations:
• ArrayList <Integer> Digits : This ArrayList will be used to store a number where
each Integer denotes a single digit. It should be declared as private. You can decide
the order of digits as you like.
• int Sign : Denotes the sign of the BigNumber. 0 (false) is positive and 1 (true) is
negative.
Methods:
• String toString( ) : Returns the number stored in the BigNumber object (ideally to
be printed).
• BigNumber Add (BigNumber Second) : Adds caller BigNumber object and the
parameter Second. Returns the result in another BigNumber instance.
2
Computer Engineering Department
• int compareTo (BigNumber Second) : returns 1 when this > second. Returns -1
when this < second. Returns 0 when this = second.
3
Computer Engineering Department
BigNumberCalculator Class
Methods:
• main () : The main method will contain a interactive menu loop. Within this loop
the user will be able to enter commands to the program (A menu/command loop
will be required in every lab for the rest of the semester). The list of commands
required are:
◦ min <X> <Y> : Find the minimum of two numbers X, Y and print
it.
◦ max <X> <Y> : Find the maximum of two numbers X, Y and print
it.
◦ add <X> <Y> : Add the numbers X, Y and print the result.
◦ sub <X> <Y> : Subtract the number X from Y and print the
result.
Where <X> and <Y> are numbers of arbitrary length, only composed of digits e.g.
9878416749456 but not 3423hi324. If the user enters any command that does not
fit any of the above, the program can respond with “Unknown command, please
enter a correct command”.