Assignment #102 and Keychains for Sale, for real this time
Code
/// Name: Brendan Baird
/// Period: 6
/// Program Name: Keychains for Sale, for real this time
/// File Name: KeychainsReal.java
/// Date Finished: 1/14/2016
import java.util.Scanner;
public class KeychainsReal
{
public static void main(String[] args)
{
Scanner k = new Scanner(System.in);
int choice;
int numberOfKeys = 0;
int pricePerKey = 10;
System.out.println("Ye Olde Keychain Shoppppe");
do
{
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("Please enter your choice: ");
choice = k.nextInt();
System.out.println();
if (choice == 1)
{
numberOfKeys = addKeychains( numberOfKeys );
System.out.println("You now have " + numberOfKeys + " keychains.");
}
else if (choice == 2)
{
numberOfKeys = removeKeychains( numberOfKeys );
System.out.println("You now have " + numberOfKeys + " keychains.");
}
else if (choice == 3)
viewOrder( numberOfKeys, pricePerKey );
else if (choice == 4)
checkout( numberOfKeys, pricePerKey );
} while (choice != 4);
}
public static int addKeychains(int numberOfKeys)
{
Scanner k = new Scanner(System.in);
int keyNumberNow;
System.out.print("You have " + numberOfKeys + " keychains. How many to add? ");
int add = k.nextInt();
keyNumberNow = numberOfKeys + add;
return keyNumberNow;
}
public static int removeKeychains(int numberOfKeys)
{
Scanner k = new Scanner(System.in);
int keyNumberNow;
System.out.print("You have " + numberOfKeys + " keychains. How many to remove? ");
int remove = k.nextInt();
keyNumberNow = numberOfKeys - remove;
return keyNumberNow;
}
public static void viewOrder( int numberOfKeys, int pricePerKey )
{
int totalCost;
System.out.println("You have " + numberOfKeys + " keychains.");
System.out.println("Keychains cost $" + pricePerKey + " each.");
totalCost = numberOfKeys * pricePerKey;
System.out.println("Total cost is $" + totalCost + ".");
}
public static void checkout( int numberOfKeys, int pricePerKey )
{
Scanner k = new Scanner(System.in);
int totalCost;
System.out.println("CHECKOUT");
System.out.println();
System.out.print("What is your name? ");
String name = k.next();
System.out.println("You have " + numberOfKeys + " keychains.");
System.out.println("Keychains cost $" + pricePerKey + " each.");
totalCost = numberOfKeys * pricePerKey;
System.out.println("Total cost is $" + totalCost + ".");
System.out.println("Thanks for your order, " + name + "!");
}
}
Picture of the output