Project 4, Project: Calculator
Code
///Name: Stella Koliavas
///Period: 5
///Program Name: Project 4
///File Name: Calculator.java
///Date Finshed: 5/31/16
import java.util.Scanner;
public class Calc
{
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("Function: ");
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 if (op.equals("^"))
c = Math.pow(a,b);
else
{
System.out.println("Undefined operator: '" + op + "'.");
c = 0;
}
System.out.println(" "+c+" ");
}} while ( a != 0 );
}
}
Picture of the output