Assignemnt #103 and Ult keychains for sale
Code
///name: Ben Borglin
///period: 6
///program name: Keychains Sale
///file name: KeychainSale.java
///date finished: 12/1/15
import java.util.Scanner;
public class KeychainSale
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int ckey, total, rem;
total = 0;
ckey = 0;
rem = 0;
System.out.println("Keychain shop");
System.out.println(" ");
System.out.println("1. Add Keychain 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: ");
int choice = keyboard.nextInt();
while (choice != 4)
{
if ( choice == 1)
ckey = addKeychains(ckey);
else if (choice == 2)
ckey = removeKeychains(ckey);
else if (choice == 3)
total = viewOrder(ckey);
else
System.out.println("ERROR: Please choose one of the options");
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.println("");
System.out.print("Your Choice: ");
choice = keyboard.nextInt();
System.out.println("");
}
checkout(ckey, total);
}
public static int addKeychains (int ckey)
{
int add;
Scanner keyboard = new Scanner(System.in);
System.out.print("You currently have " + ckey + ". How many would you like to add? ");
add = keyboard.nextInt();
ckey = add+ckey;
System.out.println("You now have " + ckey + " keychains.");
return ckey;
}
public static int removeKeychains(int ckey)
{
int rem;
Scanner keyboard = new Scanner(System.in);
System.out.print("You currently have " + ckey + ". How many would you like to remove? ");
rem = keyboard.nextInt();
if (rem > ckey)
{
System.out.println("ERROR. YOU DONT HAVE THAT MANY KEYCHAINS");
}
ckey = ckey-rem;
System.out.println("You now have " + ckey + " keychains.");
return ckey;
}
public static int viewOrder(int ckey)
{
System.out.println("You currently have " + ckey + " keychains.");
System.out.println("Keychains cost $10 each");
int total = ckey*10;
System.out.println("Total cost is $" + total);
return total;
}
public static void checkout(int ckey, int total)
{
Scanner keyboard = new Scanner(System.in);
System.out.println("CHECKOUT");
System.out.println(" ");
System.out.print("What is your name? ");
String name = keyboard.next();
System.out.println("You have " + ckey + " keychains.");
System.out.println("Total cost is $" + total + ".");
System.out.println("Thanks for you order, " + name + "!");
}
}