Assignment 102

code

///Name: Mutsu Osoegawa
///Period: 7
///Project Name: Keychains For Real this Time
///File Name: KeychainsForReal.java
///Date: 3/29/2016

import java.util.Scanner;

public class KeychainsForReal
{
    public static void main ( String[] args )
    {
        int choice, number = 0, price = 10, totalCost = 0;
        
        System.out.println("Ye Olde Keychain Shoppe");
        do
        {
            Scanner keyboard = new Scanner(System.in);
        
            System.out.println("\n1. 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("\nPlease enter your choice: ");
            choice = keyboard.nextInt();
        
            if ( choice == 1 )
                number = addKeychains(number);
            else if ( choice == 2 )
                number = removeKeychains(number);
            else if ( choice == 3 )
                totalCost = viewOrder(number, price);
            else if ( choice == 4 )
                checkout(number, totalCost);
            else 
                System.out.println("\nERROR");
                
        }while(choice != 4);
            
    }
    public static int addKeychains(int number)
    {
        Scanner kb = new Scanner(System.in);
        int total, add;
        System.out.print("\nYou have " + number + " keychains. How many to add? ");
        add = kb.nextInt();
        total = number + add;
        System.out.println("You now have " + total + " keychains.");
        return total;
    }
    public static int removeKeychains(int number)
    {
        Scanner kb = new Scanner(System.in);
        int total, remove;
        System.out.print("\nYou have " + number + " keychains. How many to remove? ");
        remove = kb.nextInt();
        total = number - remove;
        System.out.println("You now hava " + total + " keychains.");
        return total;
    }
    public static int viewOrder(int number, int price)
    {
        System.out.println("\nYou have " + number + " keychains.");
        System.out.println("Keychains cost $" + price + " each.");
        int totalCost = price * number;
        System.out.println("Total cost is $" + totalCost + ".");
        return totalCost;
    }
    public static void checkout(int number, int totalCost)
    {
        Scanner kb = new Scanner(System.in);
        String name;
        int cost = 10;
        
        System.out.println("\nCHECKOUT");
        System.out.print("\nWhat is your name? ");
        name = kb.next();
        System.out.println("You have " + number + " keychains.");
        System.out.println("Keychains cost $" + cost + " each.");
        System.out.println("Total cost is $" + totalCost + ".");
        System.out.println("Thanks for your order, " + name + "!");
    }
}