Prog 102: Keychains For Sale, real this time
///Name: Ilana Levy
///Period: 5
///Program Name: Keychains For Sale, for real this time
///File Name: keychainSale2.java
///Date Finished: 9/30/2015
import java.util.Scanner;
public class keychainSale2
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner( System.in );
int choice, keychain = 0, keyPrice = 10, add, subtract, keychainsInOrder = 0;
System.out.println( "Ye Old Keychain Shope" );
System.out.println();
do
{
System.out.println( "1. Add keychains to order\n2. Remove Keychains from Order\n3. View Current Order\n4.Checkout" );
System.out.print( "Please enter your choice: " );
choice = keyboard.nextInt();
System.out.println();
if (choice == 1 )
{
keychainsInOrder = addKeychains(keychainsInOrder);
System.out.println( "You now have " + keychainsInOrder + " keychains." );
}
else if ( choice == 2 )
{
keychainsInOrder = removeKeychains(keychainsInOrder);
System.out.println( "You now have " + keychainsInOrder + " keychains." );
}
else if ( choice == 3 )
{
String message = viewOrder(keychainsInOrder, keyPrice);
System.out.println( message );
}
else
{
String check = checkout(keychainsInOrder, keyPrice);
System.out.println( check );
}
} while (choice != 4 );
}
public static int addKeychains(int keychain)
{
Scanner keyboard = new Scanner( System.in );
String x = "ADD KEYCHAINS";
int add;
System.out.print( "You have " + keychain + " keychains. How Many to add? " );
add = keyboard.nextInt();
keychain = keychain + add;
return keychain;
}
public static int removeKeychains( int keychain )
{
Scanner keyboard = new Scanner( System.in );
String x = "REMOVE KEYCHAINS" ;
System.out.print( "You have " + keychain + " keychains. How many to remove? " );
int subtract = keyboard.nextInt();
keychain = keychain - subtract;
return keychain;
}
public static String viewOrder( int keychain, int keyPrice )
{
String x = "VIEW ORDER" , message;
message = "You have " + keychain + " keychains.\n Keychains cost $10 each.\nTotal cost is " + ( keyPrice * keychain ) ;
return message;
}
public static String checkout( int keychain, int keyPrice )
{
Scanner keyboard = new Scanner( System.in );
String x = "CHECKOUT", check, name ;
System.out.print( "What is your name? " );
name = keyboard.next();
check = "You have " + keychain + " keychains.\nKeychains cost $10 each. " + viewOrder(keychain, keyPrice) + "\nThanks for your order, " + name + "!" ;
return check;
}
}