Assignemnt #103: Keychains for Sale, real ultimate power
Code
/// Name: Kelsey Lieberman
/// Period 5
/// Program Name: RealChainz
/// File Name: RealChainz.java
/// Date Finished: 2/2/2016
import java.util.Scanner;
public class RealChainz
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int choice, end = 0, price = 10, numChainz = 0, SCPO = 5, SCPK = 1;
double salesTax = 0.0825;
do
{
System.out.println("\nYe Olde Keychain Shoppe\n\n1. Add Keychains to Order\n2. Remove Keychains from Order\n3. View Current Order\n4. Checkout");
System.out.print("\nPlease Enter Your Choice (1-4): ");
choice = keyboard.nextInt();
if (choice == 1 )
numChainz = addKeychains(numChainz);
else if (choice == 2 )
numChainz = removeKeychains(numChainz);
else if (choice == 3 )
viewOrder(numChainz, price, SCPO, SCPK, salesTax);
else if (choice == 4 )
{
checkout(numChainz, price, SCPO, SCPK, salesTax);
end = 1;
}
else
System.out.println("ERROR: Please enter a valid menu option (1-4).");
}while (end != 1 );
}
public static int addKeychains(int numChainz)
{
Scanner keyboard = new Scanner(System.in);
int add;
System.out.println("\nADD KEYCHAINS...");
System.out.print("You have " + numChainz + " keychains. How many keychains do you want to add? ");
add = keyboard.nextInt();
if (add < 0)
System.out.println("Please enter a positive number of keychainz to add. If you would like to add negative keychainz, you can subtract keychainz from your order in menu option 2.");
else
{
numChainz = numChainz + add;
System.out.println("You now have " + numChainz + " keychains.");
}
return numChainz;
}
public static int removeKeychains(int numChainz)
{
Scanner keyboard = new Scanner(System.in);
int remove;
System.out.println("\nREMOVE KEYCHAINS");
System.out.print("You have " + numChainz + " keychains.");
if (numChainz != 0)
{
System.out.print(" How many keychains do you want to remove? ");
remove = keyboard.nextInt();
if (remove < 0)
System.out.println("Please enter a positive integer. If you want to subtract negative keychainz from your order, you can add keychains to your order in menu option 1.");
else
{
numChainz = numChainz - remove;
System.out.println("You now have " + numChainz + " keychains.");
}
}
else
System.out.println("\nYou need to add keychains before you can remove any, Dingus.");
return numChainz;
}
public static void viewOrder(int numChainz, int price, int SCPO, int SCPK, double salesTax)
{
double shipping = (SCPO + (SCPK*numChainz)), subtotal = (shipping + (numChainz*price)), tax = numChainz*price*salesTax;
System.out.println("\nVIEW ORDER");
System.out.println("You have " + numChainz + " keychains.");
System.out.println("Keychains cost $" + price + " each.");
System.out.println("Initial cost is $" + (numChainz * price) + ".");
System.out.println("Shipping is $" + SCPO + " per order, plus $" + SCPK + " per keychain, for a total shipping cost of $" + shipping + ".");
System.out.println("Your Subtotal is: $" + subtotal + ".");
System.out.println("Tax is $" + tax + ".");
System.out.println("Your total is " + (tax + subtotal) + ".");
}
public static void checkout(int numChainz, int price, int SCPO, int SCPK, double salesTax)
{
Scanner keyboard = new Scanner(System.in);
double shipping = (SCPO + (SCPK*numChainz)), subtotal = (shipping + (numChainz*price)), tax = numChainz*price*salesTax;
String name;
System.out.println("\nCHECKOUT");
System.out.print("What is your name? ");
name = keyboard.next();
viewOrder(numChainz, price, SCPO, SCPK, salesTax);
System.out.println("\nThank you for visiting Ye Olde Keychain Shoppe, " + name + "!\n");
}
}
Picture of the output