// constants
final String LINE = "----------------";
final String VALUE = " +,-,*,/ value";
final String CLEAR = "Clear";
final String QUIT = "Quit ";
final int ZERO = 0;
// variables
double first;
String function;
double number;
// program code
System.out.println( "Start...");
System.out.println( "Welcome to \"SimpleCalc\" ... ");
first = 0;
// 1.Calculations
do
{
System.out.println(LINE);
System.out.println( "[" + first + "]" );
System.out.println(VALUE);
System.out.println(CLEAR);
System.out.println(QUIT);
System.out.println(LINE);
System.out.println(" SELECT :");
function = scan.next();
if (function.equals("+") || function.equals("-") || function.equals("*") || function.equals("/"))
{
number = scan.nextDouble();
if ( function.equals("+") )
{
first = first + number;
}
else if (function.equals("-") )
{
first = first - number;
}
else if (function.equals("/") )
{
first = first / number;
}
else if (function.equals("*") )
{
first = first * number;
}
}
else if (function.equals("Clear") );
{
first = ZERO;
}
}
while ( function != "q" );
//2. Exit
// todo...
System.out.println( "End.");
}
This is my code, I want to get Welcome to "SimpleCalc"...
[ 0.0 ]
+,-,*,/ value Clear
Quit
Select: + 25.0
[ 25.0 ]
+,-,*,/ value Clear
Quit
Select: / 4
[ 6.25 ]
+,-,*,/ value Clear
Quit
Select: Clear
[ 0.0 ]
+,-,*,/ value Clear
Quit
Select: q
an output like this. But something wrong and I can't find what's wrong. And I get my output like this;
Welcome to "SimpleCalc"...
[ 0.0 ]
+,-,*,/ value Clear
Quit
Select: + 25.0
[ 0.0 ]
+,-,*,/ value Clear
Quit
Select:
Thanks for help.