Assignment 103

 import java.util.Scanner;
 
 public class KeychainStore
 {
     public static void main( String[] args )
     {
         Scanner keyboard = new Scanner(System.in);
         int menu = 0, price = 10, incart = 0, shipping = 5, shippingPer = 1;
         double tax = 0.0825;
         
         System.out.println("Ye Olde Keychain Shoppe");
         while (menu !=4)
         {
             System.out.print("\n1. Add Keychains to Order\n2. Remove Keychains from Order\n3. View Current Order\n4. Checkout\n\nPlease enter your choice: ");
             menu = keyboard.nextInt();
             
             if (menu == 1)
                 incart = addKeychains(incart);
             else if (menu == 2)
                 incart = removeKeychains(incart);
             else if (menu == 3)
                 viewOrder(incart, price, tax, shipping, shippingPer);
             else if (menu ==4)
                 checkout(incart, price, tax, shipping, shippingPer);
             else
                 System.out.println("\n-ERROR-");
         }
     }
         
     public static int addKeychains(int n1)
     {
         Scanner keyboard = new Scanner(System.in);
         System.out.print("\nYou have " +n1+ " keychanis. How many to add? ");
         int n2 = keyboard.nextInt();
         while (n2 < 0)
         {
             System.out.print("Cannot add negative keychanis. How many to add? ");
             n2 = keyboard.nextInt();
         }
         
         int n3 = n1 + n2;
         System.out.println("You now have " +n3+ " keychains." );
             
         return n3;
     }
     
     public static int removeKeychains(int n1)
     {
         Scanner keyboard = new Scanner(System.in);
         System.out.print("\nYou have " +n1+ " keychanis. How many to remove? ");
         int n2 = keyboard.nextInt();
         while (n2 < 0||n2 > n1)
         {
             if (n2 < 0)
             {
                 System.out.print("Cannot remove negative keychanis. How many to remove? ");
                 n2 = keyboard.nextInt();
             }
             else if (n2 > n1)
             {
                 System.out.print("Cannot more keychains than you have. How many to remove? ");
                 n2 = keyboard.nextInt();
             }
         }
         int n3 = n1 - n2;
         System.out.println("You now have " +n3+ " keychains." );
         
         return n3;
     }
     
     public static void viewOrder(int n1, int n2, double tax, int n3, int n4)
     {
         System.out.println("\nYou have " +n1+ " keychains.");
         System.out.println("Keychains cost $" +n2+ " each.");
         System.out.println("Shipping costs $" +n3 + n1 * n4+ ".");
         System.out.println("Subtotal: $" +n3 + n1 * (n2 + n4));
         System.out.println("Tax: $" +tax * (n3 + n1 * (n2 + n4)));
         System.out.println("Total cost is $" +(1 + tax) * (n3 + n1 * (n2 + n4))+ ".");
     }
     
     public static void checkout(int n1, int n2, double tax, int n3, int n4)
     {
         Scanner keyboard = new Scanner(System.in);
         System.out.println("\nCHECKOUT\n");
         System.out.print("What is your name? ");
         String name = keyboard.next();
         viewOrder(n1, n2, tax, n3, n4);
         System.out.println("Thanks for your order, " +name+ "!");
     }
 }