Methods #103 (Can we get done with the Memechains already?)

Code

/// Name: Amir Salehi
/// Period: 7
/// Program Name: Keychains for Sale RUP
/// File Name:KeychainsforSaleRUP.java
/// Date Finished: 4/10/2016

    
 import java.util.Scanner;
    
    public class KeychainsforSaleRUP
    {
        public static void main( String[] args )
        {
            Scanner keyboard = new Scanner(System.in);
            
            System.out.println();
            System.out.println( "KEYCHAIN SHOP" );
            System.out.println();
            int choice, number, price, baseShipping, perKeyShip;
            double tax;
            
            perKeyShip = 1;
            baseShipping = 5;
            tax = 1.0825;
            number = 0;
            price = 10;
            
            do
            {
                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 )
                    number = addKeychains(number);
                
                else if ( choice == 2 )
                    number = removeKeychains(number);
                    
                else if ( choice == 3 )
                    viewOrder(number, price, tax, baseShipping, perKeyShip);
                    
                else if ( choice == 4 )
                    checkout(number, price, tax, baseShipping, perKeyShip );
                    
                else
                    System.out.println( "That is not a valid choice. Please try again." );
                
            }while ( choice != 4 );
            
        }
                                   
        public static int addKeychains(int number)
        {
            Scanner keyboard = new Scanner(System.in);
            
            int add, total;
            
            System.out.println( "You have " + number + " keychains at the moment." );
            System.out.print( "How many would you like to add? " );
            add = keyboard.nextInt();
            
            total = number + add;
            
            System.out.println( "You now have " + total + " keychains." );
            System.out.println();
            
            return total;
        }
        
        public static int removeKeychains(int number)
        {
            Scanner keyboard = new Scanner(System.in);
            
            int remove, total;
            
            System.out.println( "You have " + number + " keychains at the moment." );
            
            if ( number <= 0 )
            {
                System.out.println( "You do not have any keychains to remove." );
            }
            
            System.out.print( "How many would you like to remove? " );
            remove = keyboard.nextInt();
            
            total = number - remove;
            
            System.out.println( "You now have " + total + " keychains." );
            
            System.out.println();
            
            return total;
        }
        
        public static void viewOrder( int number, int price, double tax, int baseShipping, int perKeyShip )
        {
            int shipTotal = ( perKeyShip * number ) + baseShipping;
            int subTotal = ( number * price ) + shipTotal;
            double total = subTotal * tax;
            
            System.out.println( "You have " + number + " keychains." );
            System.out.println( "Keychains cost $10 each." );
            System.out.println( "Your shipping total is $" + shipTotal + "." );
            System.out.println( "Your subtotal is $" + subTotal + "." );
            System.out.println( "The total is $" + total + "." );
        
            System.out.println();
        }
        
        public static void checkout(int number, int price, double tax, int baseShipping, int perKeyShip )
        {
            Scanner keyboard = new Scanner(System.in);
            
            String name;
            
            System.out.println( "CHECKOUT" );
            System.out.println();
            
            System.out.print( "What is your name? " );
            name = keyboard.next();
            
            viewOrder(number, price, tax, baseShipping, perKeyShip);
            
            System.out.println( "Thanks for your order, " + name + "!" );
            System.out.println();
        }
    }  





    

Picture(s) of the output

Assignment 7

Back to Homepage