English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

You are to build a simple “English language” calculator that does the following:
• Takes three inputs from the keyboard, in the form of
x1 operator x2
where x1 & x2 are single digits (0 to 9) and the operator is a single char, +, -, *, or /.
• Outputs the description of the operation in plain English, as well as the numeric result
Constraints:
• You need to take care not to divide by zero. If the 2nd argument in the division operation is a zero, then you shall display a message “Division by zero is not allowed“
• If the number entered is more than 1 digit then display a message, “Invalid number
• If the operator is not one of the 4 preceding operators then display a message “Invalid operator”

2007-03-20 02:53:51 · 3 answers · asked by LULU 1 in Computers & Internet Programming & Design

3 answers

Well...
whats wrong here?
Do it... There is nothing difficult here..

read compare and execute... What exactly you are expecting us to reply?

2007-03-20 03:33:21 · answer #1 · answered by PC 4 · 0 0

This sounds a lot like a homework assignment.

If you go to the Java website and look up tutorials, you can find many examples that relate to the problem you are trying to solve. Check this link for "Beyond Basic Arithmetic" and combine it with argument passing from earlier tutorial sections. You'll still need to apply the logic to handle the checks that you listed and can find that in the tutorials as well.

2007-03-20 10:03:54 · answer #2 · answered by Jim Maryland 7 · 1 0

/** modify the following to suit your need **/

String msg = input.readLine();
StringTokenizer tmp = new StringTokenizer(msg, " ");
int x1 = tmp.nextToken();
char operator = tmp.nextToken();
int x2 = tmp.nextToken();

if(x1 or x2 > 9 || x1 or x2 < 0 ) // invalid number

switch(operator)
{
case '+': //addition operation
case '-': // subtraction operation
case '*': // multiplication operation
case '/':
if(x2 == 0) //Division by zero not allowed
else // Division operation
default: // invalid operator
}

//display result


/** GoOd LuCk **/

2007-03-21 06:29:35 · answer #3 · answered by Liviawarty J 2 · 0 0

fedest.com, questions and answers