StringCalculator need ASAP!!

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

Get free quotes for a project like this
Employer working
Skills Required
Project Budget
$30 - $250 USD
Total Bids
Project Description



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.

Addition/Subtraction calculator

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 – 4– 8; 16 +-18 - -1;
This line contains two calculator expressions. The first has the value -1 and the second’s value is
-10 and the third’s is -1


• Your program must read a single line of text that contains a series of addition/subtraction
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.
• 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.
• There is no restriction on the number of spaces between any two symbols.
• 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 “number plus/minus number plus/minus …”
• Don’t worry about giving error messages that recognize complex errors. For example,
you don’t have to report that there are two plusses in a row. Just complain that you
expected a number, but saw an operator.
• Once you see an error, you can stop trying to parse the rest of the expression.


• 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
• Your life will be better if you don’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’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

Welcome to the Expression Calculator
Enter a line of expressions:
---; 5 * 4 ; 6 + 15.7; - 6 ; 10 + ; ; 7
Expression 1: ERROR: “-“ is not a valid integer
Expression 2: ERROR: * is not a valid operator
Expression 3: ERROR: “.” is not a valid operator
Expression 4: ERROR: “-“ 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

Looking to make some money?

  • Set your budget and the timeframe
  • Outline your proposal
  • Get paid for your work

Hire Freelancers who also bid on this project

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