Assignment #102
Code
///Name: Cody Swain
///Period: 6
///Project Name: KeychainReal
///File Name: KeychainReal.java
///Date: 4/13/16
import java.util.Scanner;
public class KeychainReal
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int choice, price = 10, amount;
amount = 0;
System.out.println("Ye Olde Keychain Shoppe");
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.print("Please enter your choice: ");
choice = keyboard.nextInt();
while ( choice != 4 )
{
if (choice == 1){
amount = addKeychains(amount);
}
else if (choice == 2){
amount = removeKeychains(amount);
}
else if ( choice == 3){
viewOrder(amount, price);
}
else
System.out.print(" Error: Please enter a real answer. ");
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.print("Please enter your choice: ");
choice = keyboard.nextInt();
}
System.out.println();
checkout(amount, price);
}
public static int addKeychains(int amount)
{
Scanner keyboard = new Scanner(System.in);
int add, total;
System.out.println();
System.out.print("You have " + amount + " keychains. " );
System.out.print(" How many would you like to add: ");
add = keyboard.nextInt();
total = amount + add;
System.out.println("You now have have " + total + " keychains. ");
System.out.println();
return total;
}
public static int removeKeychains(int amount)
{
Scanner keyboard = new Scanner(System.in);
System.out.println();
System.out.print("You have " + amount + "keychains. " );
System.out.print(" How many would you like to remove: ");
amount = amount - keyboard.nextInt();
System.out.println("You now have have " + amount + " keychains. ");
return amount;
}
public static void viewOrder(int amount, int price)
{
Scanner keyboard = new Scanner(System.in);
System.out.println();
System.out.print("You have " + amount + " keychains. " );
System.out.println("At 10$ per keychain, the total comes out to be " + (amount*price) + " dollars. " );
System.out.println();
}
public static void checkout(int amount, int price)
{
Scanner keyboard = new Scanner(System.in);
System.out.println();
System.out.print("You have " + amount + " keychains. " );
System.out.println("At 10$ per keychain, the total comes out to be " + (amount*price) + " dollars. " );
System.out.println("Thank you for your order. ");
System.out.println();
}
}
Picture of the output