You are on page 1of 4

Computer Engineering Department

Lab Assignment 3
2020 – 2021 Fall, CMPE 211 Fundamentals of Programming II

BIG NUMBER CALCULATOR

DUE DATE: 28.10.2020 – 23:59

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.

You are asked to implement the classes;

• BigNumberCalculator. It will contain a main method.

• 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:

• Constructor : Constructor should initialize a BigNumber and populate the Digits


ArrayList using the String of number entered by the user in a command (Details
below).

• String toString( ) : Returns the number stored in the BigNumber object (ideally to
be printed).

• BigNumber Minimum (BigNumber Compared) : Compares the parameter


Compared with the caller BigNumber object (hint: basically this). Returns the
mallest.

• BigNumber Maximum (BigNumber Compared) : Same as Minimum but returns


the largest.

• BigNumber Add (BigNumber Second) : Adds caller BigNumber object and the
parameter Second. Returns the result in another BigNumber instance.
2
Computer Engineering Department

• BigNumber Substarct (BigNumber Second) : Same as Add but subtracts the


Second from the BigNumber the method is called from (this – Second).

• int compareTo (BigNumber Second) : returns 1 when this > second. Returns -1
when this < second. Returns 0 when this = second.

• Create Getters and Setters.

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.

◦ Q : Quit the program.

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”.

Look at the demo video for better understanding.

You might also like