Closed

# StringCalculator need ASAP!!

This project received 10 bids from talented freelancers with an average bid price of \$48 USD.

\$30 - \$250 USD
10
###### Project Description

NEED THIS DONE IN 2 HOURS (1AM EST, MIDNIGHT CENTRAL). 40\$

Introduction

Many programs have to manipulate String objects in interesting ways. The String class is also

well designed and provides many useful methods. So, this assignment will give you some

practice with it.

You will write a simple calculator program that only performs addition and subtraction.

Your program will compute numeric values based on what the user enters in a single line of text.

Here are some example lines:

-5 + 6 - 2 ; 2 &ndash; 4&ndash; 8; 16 +-18 - -1;

This line contains two calculator expressions. The first has the value -1 and the second&rsquo;s value is

-10 and the third&rsquo;s is -1

Requirements

expressions. Each expressions will be terminated by a semicolon (except when there is

an error). If the last expression does not end with a semicolon, that is an error.

&bull; The numbers should be only integers. They may have a leading minus sign to indicate a

negative value. The minus sign should not be separated from the first digit of the integer.

&bull; There is no restriction on the number of spaces between any two symbols.

&bull; Your program must give error messages in the following cases:

o A missing semi-colon on the last expression

o The use of any operator other than + or -

o Any deviation from the pattern of &ldquo;number plus/minus number plus/minus &hellip;&rdquo;

&bull; Don&rsquo;t worry about giving error messages that recognize complex errors. For example,

you don&rsquo;t have to report that there are two plusses in a row. Just complain that you

expected a number, but saw an operator.

&bull; Once you see an error, you can stop trying to parse the rest of the expression.

Suggestions

&bull; Our solution uses all of the following methods. There are alternate solutions that might

use a different mix, but for us, this was the easiest path

o From the String class: charAt, substring, trim, split, and indexOf

o From the Character class: isDigit, and isLetter

&bull; Your life will be better if you don&rsquo;t try to put everything in the main method. You might

consider having a method like this:

o public static double parseCalculatorExpression(String decl)

This method is called by main() and handles a single calculator expression. It

assumes that its argument has had the semicolon removed and then been trimmed

Sample Output

We&rsquo;ll provide sample output later

Welcome to the Expression Calculator

Enter a line of expressions:

-5 + 6 - 2 ; 2 - 4- 8; 16 +-18 - -1; 1 --2;

Expression 1: value = -1

Expression 2: value = -10

Expression 3: value = -1

Expression 4: value = 3

Goodbye!

Welcome to the Expression Calculator

Enter a line of expressions:

---; 5 * 4 ; 6 + 15.7; - 6 ; 10 + ; ; 7

Expression 1: ERROR: &ldquo;-&ldquo; is not a valid integer

Expression 2: ERROR: * is not a valid operator

Expression 3: ERROR: &ldquo;.&rdquo; is not a valid operator

Expression 4: ERROR: &ldquo;-&ldquo; is not a valid integer

Expression 5: ERROR: expression did not end with an integer

Expression 6: ERROR: empty expression

Expression 6: value = 7

ERROR: final expression not terminated with a semicolon

Goodbye!

## Hire Freelancers who also bid on this project

• Forbes
• The New York Times
• Time
• Wall Street Journal
• Times Online