Assignemnt #103
Code
//colin hinton
//5th period
//Keychain.java
//2/22/2015
import java.util.Scanner;
public class Keychain
{
public static void main (String [] args)
{
System.out.println("Welcome to me shop");
Scanner kb = new Scanner(System.in);
int bulk = 0;
int option;
do
{
System.out.println("1) Add keychains to order");
System.out.println("2) Remove keychains to order");
System.out.println("3) View current order");
System.out.println("4) Checkout");
System.out.print("Please enter a choice ");
option = kb.nextInt();
while(option > 4)
{
System.out.print("Please enter one of the four options: ");
option = kb.nextInt();
}
if (option == 1)
{
bulk = Add(bulk);
}
else if (option == 2)
{
bulk = Remove(bulk);
}
else if (option == 3)
{
View(bulk);
}
else if (option == 4)
{
End(bulk);
}
}while (option != 4);
}
public static int Add(int bulkOne)
{
Scanner kb = new Scanner(System.in);
System.out.println();
System.out.print("You have " + bulkOne + " keychains, how many would you like to add ");
int addition = kb.nextInt();
while (addition < 0)
{
System.out.print("Please enter a number great than or equal to zero ");
addition = kb.nextInt();
}
int bulk = addition + bulkOne;
System.out.println("You now have " + bulk + " keychains");
return bulk;
}
public static int Remove(int bulkTwo)
{
Scanner kb = new Scanner(System.in);
System.out.println();
System.out.print("You have " + bulkTwo + " keychains, how many would you like to remove ");
int subtract;
subtract = kb.nextInt();
while (subtract > bulkTwo)
{
System.out.print("Please enter a number less than or equal to your total ");
subtract = kb.nextInt();
}
int bulk = bulkTwo - subtract;
System.out.println("You now have " + bulk + " keys");
return bulk;
}
public static void View(int bulkThree)
{
System.out.println();
System.out.println("You have " + bulkThree + " keychains");
System.out.println("Keychains cost $10 dollars each");
int total = 10*bulkThree;
Double tax = total * .0875;
Double taxTotal = tax + total;
Double totalReal = taxTotal + 5 + bulkThree;
System.out.println("Total cost is " + total);
System.out.println("Those items will be taxed for " + taxTotal);
System.out.println("There will also be a flat rate of $5 for shipping plus $" + bulkThree);
System.out.println("The total will be $" + totalReal);
}
public static void End(int bulkThree)
{
Scanner kb = new Scanner(System.in);
System.out.println();
System.out.print("What is your name? ");
String name;
name = kb.next();
View(bulkThree);
System.out.println("Thanks for your order, " + name);
}
}
Picture of the output