Program #107

Code

   
    /// Name: Afaf Nabeeha
    /// Period: 7
    /// Program Name: Baby Calculator
    /// File Name: Baby.java
    /// Date Finished: 3/8/2016 public class Baby

        import java.util.Scanner;
        
        public class Baby
        {
        	public static void main( String[] args )
        	{
        		Scanner keyboard = new Scanner(System.in);
                System.out.println( "Calculator" );
                Double first, second, third;
                String operation;
                do 
                {
                    System.out.print( "> " );
                    first = keyboard.nextDouble();
                    operation = keyboard.next();
                    second = keyboard.nextDouble();
                    if ( operation.equals("+") )
                    {
                        third = first + second;
                    }
                    else if ( operation.equals("-"))
                    {
                        third = first - second;
                    }
                    else if ( operation.equals("*"))
                    {
                        third = first * second;
                    }
                    else if ( operation.equals("/"))
                    {
                        third = first / second;
                    }
                    else 
                    {
                        System.out.println( "Undefined operation '" + operation + "'. " );
                        third = 0.0;
                    }
                    System.out.println(third);
                } while (first != 0);
                System.out.println( "Bye, now. ");
                                   
            }
        }

             
    

Picture of the output

Assignment 107