Assignment #102 and Key Chains For Real
Code
/// Name: Graham Pollock
/// Period: 5
/// Program Name: Key Chains For Real
/// File Name: KeyChainsForReal.java
/// Date Finished: 03/29/2016/
import java.util.Scanner;
public class KeyChainsForReal
{
public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);
int number, price;
number = 0;
price = 10;
System.out.println("The Kaychain shop");
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: ");
int choice = kb.nextInt();
System.out.println("");
while (choice != 4)
{
if ( choice == 1)
{
number = addKeychains(number);
}
else if (choice == 2)
number = removeKeychains(number);
else if (choice == 3)
viewOrder(number, price);
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 = kb.nextInt();
System.out.println("");
}
checkout(number, price);
}
public static int addKeychains(int number)
{
Scanner kb = new Scanner(System.in);
int total, add;
System.out.print("You have " + number + " keychains. Add how many? ");
add = kb.nextInt();
total = number + add;
System.out.println("You now have " + total + " keychains");
return total;
}
public static int removeKeychains(int number)
{
Scanner kb = new Scanner(System.in);
int total, take;
System.out.print("You have " + number + " keychains. Remove how many? ");
take = kb.nextInt();
total = number - take;
System.out.println("You now have " + total + " keychains");
return total;
}
public static void viewOrder(int number, int price)
{
int total = number * price;
System.out.println("You currently have " + number + " keychains.");
System.out.println("Each keychain is $" + price + ".");
System.out.println("Your total cost is $" + total + ".");
}
public static void checkout(int number, int price)
{
Scanner kb = new Scanner(System.in);
int total = number * price;
System.out.print("What is you name? ");
String name = kb.next();
System.out.println(name + ", you have " + number + " keychains.");
System.out.println("Total cost of " + total + ".");
System.out.println("Thank you for your order, " + name);
}
}
Picture of the output