Assignemnt # 103

Code

      ///Name: Dakota Donahue
      ///Period: 5
      ///Project Name:
      ///File Name:
      ///Date: 4/29/2016
      
      import java.util.Scanner;

      public class KeychainsForRealUltimate
      {
          public static void main( String[] args )
          {
          
              Scanner bot = new Scanner(System.in);
              System.out.println("Ye Olde Keychain Shoppe");
              System.out.println();
              
              int selection = 0, keyNum = 0, keyCost = 10;
              double salesTax = .0825, shipping = 5.00, perKeychainShipping = 1.00;
              
              
              
              while ( selection != 4 )
              {
                  System.out.println("1.\tAdd Keychains to Order");
                  System.out.println("2.\tRemove Keychains from Order");
                  System.out.println("3.\tView Current Order");
                  System.out.println("4.\tCheckout");
                  System.out.println("");
                  
                  System.out.println("Please enter your choice: ");
                  selection = bot.nextInt();
                  
                  if ( selection == 1 )
                      keyNum=addKeychains(keyNum);
                  else if ( selection == 2 )
                      keyNum=removeKeychains(keyNum);
                  else if ( selection == 3 ) 
                      viewOrder(keyNum,keyCost,salesTax,shipping,perKeychainShipping);
                  else if ( selection == 4 )
                      checkout(keyNum,keyCost,salesTax,shipping,perKeychainShipping);
                  else
                  {
                      while ( selection > 4 || selection < 1 );
                      {
                          System.out.println("Whoops. You didn't select a valid option. Try again.");
                          
                          System.out.println("");
                          System.out.println("1.\tAdd Keychains to Order");
                          System.out.println("2.\tRemove Keychains from Order");
                          System.out.println("3.\tView Current Order");
                          System.out.println("4.\tCheckout");
                          System.out.println("");
      
                          System.out.println("Please enter your choice: ");
                          selection = bot.nextInt();
                          
                      }
                  }
                  
              }
          
          }
          
          public static int addKeychains( int keys )
          {   
              int keyDiff;
              Scanner bot = new Scanner(System.in);
              System.out.println("ADD KEYCHAINS");
              System.out.println("");
              
              System.out.println("You have " + keys + ". How many would you like to add?");
              keyDiff =  bot.nextInt();
              keys = keys + keyDiff;
              
              System.out.println("");
              System.out.println("You now have " + keys + " keychains.");
              System.out.println("");
              
              return keys;
          }
          
          public static int removeKeychains( int keys )
          {
              int keyDiff;
              ;
              Scanner bot = new Scanner(System.in);
              System.out.println("REMOVE KEYCHAINS");
              System.out.println("");
              
              System.out.println("You have " + keys + ". How many would you like to remove?");
              keyDiff = bot.nextInt();
              
              
              int test = keys - keyDiff;
              
              while ( test < 0 )
              {
                  System.out.println("Whoops. Can't have negative keychains.");
                  System.out.println("Try again: ");
                  keyDiff = bot.nextInt();
                  
                  test = keys - keyDiff;
              }
              
              keys = keys - keyDiff;
              
              System.out.println("");
              return keys;
          }
          
          public static void viewOrder( int keys, int keyPrice, double salesTax, double shipping, double perKeychainShipping )
          {        
              System.out.println("VIEW ORDER");
              System.out.println("");
              
              double salesTaxMultiplier = 1 - salesTax;
              
              double total = keys*keyPrice*salesTaxMultiplier + shipping + perKeychainShipping*keys;
              
              System.out.println("You have " + keys + ".");
              
              if ( keys <= 0 )
                  System.out.println("Keychains cost $10 each, meaning your total is $0.00.");
              else 
                  System.out.println("Keychains cost $10 each, meaning your total is $" + total + ".");
                 
                       
              System.out.println("");
              
          }
          
          public static void checkout( int keys, int keyPrice, double salesTax, double shipping, double perKeychainShipping )
          {   
              Scanner bot = new Scanner(System.in);
              System.out.println("CHECKOUT");
              System.out.println("");
              
              
              System.out.println("What is your name?");
              String name = bot.next();
              double salesTaxMultiplier = 1 - salesTax;
              
              double total = keys*keyPrice*salesTaxMultiplier + shipping + perKeychainShipping*keys;
              
              if ( keys <= 0 )
                  System.out.println("Keychains cost $10 each, meaning your total is $0.00.");
              else 
                  System.out.println("Keychains cost $10 each, meaning your total is $" + total + ".");
              
              System.out.println("");
              System.out.println("Thanks for your order, " + name + "!");
          }
          
      
      }
      
      
    
ALettertoYourself