Assignment 107, Baby Calc Review
Code
///Name: Stella Koliavas
///Period: 5
///Program Name: Baby Calc 2
///File Name: BabyCalc2.java
///Date Finshed: 5/3/16
import java.util.Scanner;
public class BabyCalc2
{
public static void main( String[] args )
{
Scanner siri = new Scanner(System.in);
double a, b, c;
String op;
do
{
System.out.print("> ");
System.out.print("First number: ");
a = siri.nextDouble();
if (a == 0)
System.out.println("Thanks for calculating!");
else if (a != 0)
{
System.out.print(" Divide (/), mulitiple (*), add (+), or subtract (-)? ");
op = siri.next();
System.out.print(" Second number: ");
b = siri.nextDouble();
if (op.equals("+"))
c = (a + b);
else if (op.equals("-"))
c = (a - b);
else if (op.equals("/"))
c = (a/b);
else if (op.equals("*"))
c = (a*b);
else
{
System.out.println("Undefined operator: '" + op + "'.");
c = 0;
}
System.out.println(" "+c+" ");
}} while ( a != 0 );
}
}
Picture of the output