Assignment #102 and Keychains for Sale, for real this time
Code
/// Name: Ali Kurland
/// Period: 6
/// Program Name: Keychains for Sale, for real this time
/// File Name: RealKeychains.java
/// Date Finished: 12/7/2015
import java.util.Scanner;
public class RealKeychains
{
public static void main ( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int choice, numKeychains = 0, perKeychain = 10;
System.out.println("Super Cool Keychain Shop");
do
{
System.out.println("\n1. 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("\nPlease enter your choice: ");
choice = keyboard.nextInt();
if ( choice == 1 )
{
numKeychains = addKeychains(numKeychains);
}
else if ( choice == 2 )
{
numKeychains = removeKeychains(numKeychains);
}
else if (choice == 3)
{
viewOrder(numKeychains,perKeychain);
}
else
{
checkout(numKeychains,perKeychain);
}
}while ( choice != 4 );
}
public static int addKeychains( int numKeychains )
{
Scanner keyboard = new Scanner(System.in);
System.out.print("\nYou have " + numKeychains + " keychains. How many to add? ");
int add = keyboard.nextInt();
numKeychains = numKeychains + add;
System.out.print("You now have " + numKeychains + " keychains.\n");
return numKeychains;
}
public static int removeKeychains( int numKeychains )
{
Scanner keyboard = new Scanner(System.in);
System.out.print("\nYou have " + numKeychains + " keychains. How many to remove? ");
int remove = keyboard.nextInt();
numKeychains = numKeychains - remove;
System.out.print("You now have " + numKeychains + " keychains.\n");
return numKeychains;
}
public static void viewOrder( int numKeychains, perKeychain )
{
System.out.println( "\nYou have " + numKeychains + " keychains. " );
System.out.println( "Keychains cost $" + perKeychain + " each. " );
System.out.println( "Total cost is $" + ( numKeychains * perKeychain ) + "." );
}
public static void checkout( int numKeychains, perKeychain )
{
Scanner keyboard = new Scanner(System.in);
System.out.println("\nCHECKOUT\n");
System.out.print( "What is your name? " );
String name = keyboard.next();
viewOrder(numKeychains,perKeychain);
System.out.println( "Thanks for your order, " + name + "!" );
}
}
Picture of the output