Assignment #103

Code

    
    ///Name: Cody Swain
    ///Period: 6
    ///Project Name: KeychainSale
    ///File Name: KeychainSale.java
    ///Date: 4/18/16
    
    
    
        import java.util.Scanner;

        public class KeychainSale
        {
            public static void main( String[] args )
            {
    
                Scanner keyboard = new Scanner(System.in);
                int choice, price = 10, amount = 0, pricePerKeychain = 1, baseShipping = 5;
                double tax = 1.0825;
    
                System.out.println("Ye Olde Keychain Shoppe");
                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.print("Please enter your choice: ");
                choice = keyboard.nextInt();
    
                while ( choice != 4 )
                {
                    if (choice == 1){
                        amount = addKeychains(amount);
                    }
                    else if (choice == 2){
                        amount = removeKeychains(amount);
                    }
                    else if ( choice == 3){
                        viewOrder(amount, price, baseShipping, pricePerKeychain, tax);
                    }
                    else
    
                    System.out.print(" Error: Please enter a real answer. ");
                    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.print("Please enter your choice: ");
                    choice = keyboard.nextInt();
                }
    
                System.out.println();
                checkout(amount, price, baseShipping, pricePerKeychain, tax);
    
            }
    
    
    
    
                public static int addKeychains(int amount)
                {
                    Scanner keyboard = new Scanner(System.in);
                    int add, total;
                    System.out.println();
                    System.out.print("You have " + amount + " keychains. " );
                    System.out.print(" How many would you like to add: ");
                    add = keyboard.nextInt();
                    if ( add < 0)
                        add =  -add; 
                    total = amount + add;
                    System.out.println("You now have have " + total + " keychains. ");
                    System.out.println();
                    return total;
    
                }
                public static int removeKeychains(int amount)
                {
                    int remove, total;
                    Scanner keyboard = new Scanner(System.in);
                    System.out.println();
                    System.out.print("You have " + amount + " keychains. " );
                    System.out.print(" How many would you like to remove: ");
                    remove = keyboard.nextInt();
                    if ( remove < 0 )
                        remove = -remove;
                    total = amount - remove;
                    System.out.println("You now have have " + total + " keychains. ");
                    return total;
    
                }
                public static void viewOrder(int amount, int price, int baseShipping, int pricePerKeychain, double tax)
                {
                    Scanner keyboard = new Scanner(System.in);
                    System.out.println();
                    System.out.println("You have " + amount + " keychains. " );
                    System.out.println("Each keychain is " + price + " dollars. ");
                    System.out.println("Shipping is " + (baseShipping+((pricePerKeychain)*amount)) + " dollars. ");
                    double subtotal = ((amount*price)+(baseShipping+((pricePerKeychain)*amount)));
                    System.out.println("Your subtotal is " + subtotal);
                    double total = (subtotal*tax);
                    System.out.println("With a 8.25% tax rate your total comes out to be " + total + " dollars. " );
                    System.out.println();
                }
                public static void checkout(int amount, int price, int baseShipping, int pricePerKeychain, double tax)
                {   
                    Scanner keyboard = new Scanner(System.in);
                    System.out.print("What is your name: ");
                    String firstName = keyboard.next(), lastName = keyboard.next();
                    System.out.println(" Okay, " + firstName + " " + lastName + ".");
                    viewOrder(amount, price, baseShipping, pricePerKeychain, tax);
                }
        }
    
        

    



    

Picture of the output

Assignment 103