Assignemnt #102 Keychains for Sale, for real this time
Code
///Name: Prooz Fereydouni
///Period: 7
///Project Name: Keychains for Sale, for real this time
///File Name: KfS2.java
///Date: 3/31/2016
import java.util.Scanner;
public class KfS2
{
public static void main( String[] args)
{
Scanner kb = new Scanner(System.in);
int cost = 20;
int keys = 0;
System.out.println("Keychain Store");
System.out.println("");
int answer = 0;
do
{
System.out.println("1. Add keychains");
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: ");
answer = kb.nextInt();
if (answer == 1) keys = AddKeychain(keys);
if (answer == 2) keys = RemoveKeychain(keys);
if (answer == 3) ViewOrder(keys, cost);
if (answer == 4) Checkout(keys, cost);
}while(answer!=4);
}
public static int AddKeychain(int key)
{
Scanner kb = new Scanner(System.in);
System.out.print("You have " + key + " keychains. How many to add? ");
int add = kb.nextInt();
key = add + key;
System.out.println("You now have " + key + " keys.");
return key;
}
public static int RemoveKeychain(int key)
{
Scanner kb = new Scanner(System.in);
System.out.print("You have " + key + " keychains. How many to remove? ");
int remove = kb.nextInt();
key = key - remove;
System.out.println("You now have " + key + " keys.");
return key;
}
public static void ViewOrder(int key, int cost)
{
System.out.println("You have " + key + " keychains.");
System.out.println("They each cost $" + cost + ".");
int TotalCost = key * cost;
System.out.println("Total cost is $" + TotalCost + ".");
}
public static void Checkout(int key, int cost)
{
Scanner kb = new Scanner(System.in);
System.out.print("What is your name? ");
String name = kb.next();
System.out.println("You have " + key + " keychains.");
System.out.println("Keychains cost $" + cost + " each.");
int TotalCost = key * cost;
System.out.println("Total cost is $" + TotalCost + ".");
System.out.println("Thanks for your order, " + name + "!");
}
}
Picture of the output