Assignment 102
import java.util.Scanner;
public class KeychainStore
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int menu = 0, price = 10, incart = 0;
System.out.println("Ye Olde Keychain Shoppe");
while (menu !=4)
{
System.out.print("\n1. Add Keychains to Order\n2. Remove Keychains from Order\n3. View Current Order\n4. Checkout\n\nPlease enter your choice: ");
menu = keyboard.nextInt();
if (menu == 1)
incart = addKeychains(incart);
else if (menu == 2)
incart = removeKeychains(incart);
else if (menu == 3)
viewOrder(incart, price);
else if (menu ==4)
checkout(incart, price);
else
System.out.println("\n-ERROR-");
}
}
public static int addKeychains(int n1)
{
Scanner keyboard = new Scanner(System.in);
System.out.print("\nYou have " +n1+ " keychanis. How many to add? ");
int n2 = keyboard.nextInt();
int n3 = n1 + n2;
System.out.println("You now have " +n3+ " keychains." );
return n3;
}
public static int removeKeychains(int n1)
{
Scanner keyboard = new Scanner(System.in);
System.out.print("\nYou have " +n1+ " keychanis. How many to remove? ");
int n2 = keyboard.nextInt();
int n3 = n1 - n2;
System.out.println("You now have " +n3+ " keychains." );
return n3;
}
public static void viewOrder(int n1, int n2)
{
System.out.println("\nYou have " +n1+ " keychains.");
System.out.println("Keychains cost $" +n2+ " each.");
System.out.println("Total cost is $" +n1 * n2+ ".");
}
public static void checkout(int n1, int n2)
{
Scanner keyboard = new Scanner(System.in);
System.out.println("\nCHECKOUT\n");
System.out.print("What is your name? ");
String name = keyboard.next();
System.out.println("You have " +n1+ " keychains.");
System.out.println("Keychains cost $" +n2+ " each.");
System.out.println("Total cost is $" +n1 * n2+ ".");
System.out.println("Thanks for your order, " +name+ "!");
}
}