StringCalculator need ASAP!!



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


Habilidades: Java

Veja mais: assignment, what need for an operator, what is substring, substring in c, substring c, substring 0 2, string pattern, string c plus plus, pattern string, method to write a report, integers and, first class solutions, first class objects in java, final trim, est java, c substring, c string substring, c string pattern, c# programs with output, c plus plus string

Acerca do Empregador:
( 0 comentários ) New Berlin, United States

ID do Projeto: #2516606

10 freelancers estão ofertando em média $48 para esse trabalho


Hello, I am expert and dedicated in JAVA Development.I am very much interested for your project. I can complete your project quickly and efficiently in time. Details will be discussed in the message. I will be able to Mais

$50 USD in 0 dias
(244 Comentários)

Hi, Please let me do it.

$150 USD in 2 dias
(3 Comentários)

This is a very simple java project for me...Can do this for you within a day....

$30 USD em 1 dia
(10 Comentários)

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ Let's begin just now........... $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ Mais

$30 USD in 0 dias
(2 Comentários)

Hello, I can develop your application in less then 2 hours for 30$. Please see my resume for details on my skills and experience collected. I'm looking forward to hearing from you. Best wishes, Cornel

$30 USD em 1 dia
(0 Comentários)

Sir, We are group of IT Graduates really excelled in our [login to view URL] is at prime in our area of [login to view URL] with us would really give you best quality of work with optimum [login to view URL] looking forward of he Mais

$50 USD in 2 dias
(0 Comentários)

I can deliver good quality solution in no time

$30 USD in 0 dias
(0 Comentários)

Already done a similar assignment, ready to start now. Thanks.

$50 USD in 2 dias
(0 Comentários)

Hi rdsoto, We will deliver a quality product in time, please let us do this for you. Thank you, Kartheek

$30 USD in 0 dias
(0 Comentários)

I can do that...

$30 USD em 1 dia
(0 Comentários)