#103

Code

  /// Name: Josh Bautista
  /// Period: 6
  /// Program Name: Key Chains for sale 3
  /// File Name: KFS3.java
  /// Date Finished: 2/26/2015
  
  import java.util.Scanner;
    
    public class KFS3
    {
    	public static void main( String[] args )
    	{
            Scanner keyboard = new Scanner(System.in);
            int keychains, choice, ship, xkeychain;
            String name;
            Double cost, tax;
            
            choice = 0;
            keychains = 0;
            cost = 10.00;
            tax = .0825;
            ship = 5;
            xkeychain = keychains - 1;
            
            System.out.println();
            System.out.println( "Ye Olde Keychain Shoppe" );
            
            while ( choice != 4 )
            {
                System.out.println();
                System.out.println( "1. Add Keychains to Order" );
                System.out.println( "2. Remove Keychains from Order" );
                System.out.println( "3. View Current Order" );
                System.out.println( "4. Checkout" );
                System.out.println();
                System.out.print( "Please enter your choice: " );
                choice = keyboard.nextInt();
                System.out.println();
                
                if ( choice == 1 )
                {
                    keychains = addKeychains( keychains );
                    xkeychain = keychains - 1;
                }
                
                else if ( choice == 2 )
                {
                    keychains = removeKeychains( keychains );
                    xkeychain = keychains - 1;
                }
                
                else if ( choice == 3 )
                {
                    viewOrder( keychains, cost, tax, ship, xkeychain );
                }
                
                else if ( choice == 4 )
                {
                    checkout( keychains, cost, tax, ship, xkeychain );
                }
                else
                {
                    System.out.println( "Error, please select an option" );
                }
            }
            System.out.println();
        }
        
        public static int addKeychains( int keychains )
    	{
            int add, total;
            Scanner keyboard = new Scanner(System.in);
    		System.out.print( "You have " + keychains + " keychains.  How many to add? " );
            add = keyboard.nextInt();
            while ( add < 0 )
            {
                System.out.print( "Invalid amount to remove.  Please select a positive number. " );
                add = keyboard.nextInt();
            }
            total = keychains + add;
            System.out.println( "You now have " + total + " keychains." );
            return total;
    	}
        
        public static int removeKeychains( int keychains )
    	{
            int remove, total;
            Scanner keyboard = new Scanner(System.in);
    		System.out.print( "You have " + keychains + " keychains.  How many to remove? " );
            remove = keyboard.nextInt();
            
            while ( remove > keychains || remove < 0 )
            {
                System.out.print( "Invalid amount to remove.  Please select a positive number less than or equal to your current amount of keychains. " );
                remove = keyboard.nextInt();
            }
            total = keychains - remove;
            System.out.println( "You now have " + total + " keychains." );
            return total;
    	}
        
        public static void viewOrder( int keychains, Double cost, Double tax, int ship, int xkeychain )
    	{
            int shipping;
            Double total, subtotal, orderTax;
            Scanner keyboard = new Scanner(System.in);
    		System.out.println( "You have " + keychains + " keychains." );
            System.out.println( "Keychains cost $10 each." );
            shipping = ship + xkeychain;
            System.out.println( "Total shipping cost is $" + shipping + "." );
            subtotal = cost*keychains + shipping;
            System.out.println( "Subtotal is $" + subtotal + "." );
            orderTax = tax*subtotal;
            System.out.println( "The tax on the order is $" + orderTax + "." );
            total = subtotal + orderTax;
            System.out.println( "Total cost is $" + total + "." );
    	}
        
        public static void checkout( int keychains, double cost, double tax, int ship, int xkeychain )
    	{
            int shipping;
            String name;
            Double total, subtotal, orderTax;
            Scanner keyboard = new Scanner(System.in);
    		System.out.println( "CHECKOUT" );
            System.out.println();
            System.out.print( "What is your name? " );
            name = keyboard.next();
            System.out.println( "You have " + keychains + " keychains." );
            System.out.println( "Keychains cost $10 each." );
            shipping = ship + xkeychain;
            System.out.println( "Total shipping cost is $" + shipping + "." );
            subtotal = cost*keychains + shipping;
            System.out.println( "Subtotal is $" + subtotal + "." );
            orderTax = tax*subtotal;
            System.out.println( "The tax on the order is $" + orderTax + "." );
            total = subtotal + orderTax;
            System.out.println( "Total cost is $" + total + "." );
            System.out.println( "Thank you for your order, " + name + "!" );
    	}
    }
    

Picture of the output

Assignment 4