Assignemnt #102 and Real Keychain Store
Code
///Name: Daniel Tiffany-Appleton
///Period: 7
///Program Name: Real Keychain Store
///File Name: RealKeychainStore
///Date Finished: 3/8/16
import java.util.Scanner;
public class RealKeychainStore
{
public static void main( String args[] )
{
Scanner keyboard = new Scanner(System.in);
int choice, keychains, cost;
String name;
System.out.println("Ye Olde Keychain Shoppe");
System.out.println(" ");
choice = 0;
keychains = 0;
cost = 0;
name = "bob";
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();
if( choice == 1 )
{
keychains = addKeychains(keychains);
System.out.println("You now have " + keychains + " keychains.");
System.out.println(" ");
}
else if ( choice == 2 )
{
keychains = removeKeychains(keychains);
System.out.println("You now have " + keychains + " keychains.");
System.out.println(" ");
}
else if ( choice == 3 )
{
cost = viewOrder(keychains);
System.out.println("Total cost is $" + cost + ".");
System.out.println(" ");
}
else if ( choice == 4 )
{
name = checkout(keychains, cost);
System.out.println("Thanks for your order, " + name + "!");
}
else
{
System.out.println("Not a choice.");
}
}while( choice != 4 );
}
public static int addKeychains(int keychains)
{
Scanner keyboard = new Scanner(System.in);
int add;
System.out.println(" ");
System.out.print("You have " + keychains + " keychains. How many to add? ");
add = keyboard.nextInt();
keychains = keychains + add;
return keychains;
}
public static int removeKeychains(int keychains)
{
Scanner keyboard = new Scanner(System.in);
int subtract;
System.out.println(" ");
System.out.print("You have " + keychains + " keychains. How many to remove? ");
subtract = keyboard.nextInt();
keychains = keychains - subtract;
return keychains;
}
public static int viewOrder(int keychains)
{
int cost;
System.out.println(" ");
System.out.println("You have " + keychains + " keychains.");
System.out.println("Keychains cost $10 each.");
cost = keychains * 10;
return cost;
}
public static String checkout(int keychains, int cost)
{
Scanner keyboard = new Scanner(System.in);
String name;
System.out.print("What is your name? ");
name = keyboard.next();
System.out.println("You have " + keychains + " keychains.");
System.out.println("Keychains cost $10 each.");
System.out.println("Total cost is " + cost + ".");
return name;
}
}
Picture of the output