Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA: Need help for this JAVA question As you know, in Java integers have a range that has a minimum value of 2.147.483.648 and a

JAVA: Need help for this JAVA question

image text in transcribed

As you know, in Java integers have a range that has a minimum value of 2.147.483.648 and a maximum value of 2,147.483,647. It is a pretty large range, but it is possible that one can encounter even larger numbers. In this lab, our aim is to write a computer program that is able to do arithmetic operations with even larger numbers. In this assignment, you are asked to implement a class called "Calculator It will contain a main method . It will contain a class called "BigNumber" which stores a list of numbers (Java files can have more than one class, but only a single public class) The purpose of this exercise is To remember the programmings skills To remember how to use arrays To remember how to use loops Example: Take the number 56897531 Array of integers digits will be represented as: 6 8 9 7 BigNumber Data Declarations: int digits: The array "digits" is used to store a list of integers. Every integer is a digit of the BigNumber and it should be declared as private int Sign: denotes the sign of the Number. A 0 denotes a positive number and a l denotes a negative number. Methods Constructor 1: (BigNumber(String number)) First constructor Constructor 2: (BigNumber(intll digits)) Second constructor should take an array of integers as argument and assign it to digits variable. (When doing arithmetic operations, you would like to create a BigNumber from an array list, skipping keyboard input that is provided by constructor 1) int getLength) returns the number of elements in the Array List. Naturally corresponds to the number of digits the large number has String toString0: returns the number stored on Array List as well as the sign as human readable string to be used in print statements. int compareTo(BigNumber other): compares the big number the method is invoked from to the argument big number other. If they are equal, the method returns 0. if other big number is larger, it returns -1. otherwise it returns 1 BigNumber add(BigNumber second): Adds the second BigNumber to the one method is called from. Returns the result as another BigNumber (Hint: use the second constructor to quickly create a BigNumber via an integer array) BigNumber subtract(BigNumber second): Subtracts two BigNumbers. Returns the result as another BigNumber Calculator Methods main ( ): The main method will contain a loop. Within this loop the user will interact with the program. The program will ask the user to enter a command until the user enters special command "Q". which will terminate the program. Following every command, the user will input two BigNumbers on different lines. Possible commands are FindMin: Find the minimum of the numbers and print it. FindMax: Find the maximum of numbers and print it. Add: Find the sum of numbers and print it. Sub: Find the result of X - Y and print it. Q: quits the program Any other command will be responded with "Unknown Command, please enter a correct command

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

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions