#102
Code
/// Name: Josh Bautista
/// Period: 6
/// Program Name: Key Chains for sale 2
/// File Name: KC2.java
/// Date Finished: 2/26/2015
import java.util.Scanner;
public class KC2
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int keychains, choice, cost;
String name;
choice = 0;
keychains = 0;
cost = 10;
System.out.println();
System.out.println( "Ye Olde Keychain Shoppe" );
while ( choice != 4 )
{
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 = keyboard.nextInt();
System.out.println();
if ( choice == 1 )
{
keychains = addKeychains( keychains );
}
else if ( choice == 2 )
{
keychains = removeKeychains( keychains );
}
else if ( choice == 3 )
{
viewOrder( keychains, cost );
}
else if ( choice == 4 )
{
checkout( keychains, cost );
}
else
{
System.out.println( "Error, please select an option" );
}
}
System.out.println();
}
public static int addKeychains( int keychains )
{
int add, total;
Scanner keyboard = new Scanner(System.in);
System.out.print( "You have " + keychains + " keychains. How many to add? " );
add = keyboard.nextInt();
total = keychains + add;
System.out.println( "You now have " + total + " keychains." );
return total;
}
public static int removeKeychains( int keychains )
{
int remove, total;
Scanner keyboard = new Scanner(System.in);
System.out.print( "You have " + keychains + " keychains. How many to remove? " );
remove = keyboard.nextInt();
total = keychains - remove;
System.out.println( "You now have " + total + " keychains." );
return total;
}
public static void viewOrder( int keychains, int cost )
{
int total;
Scanner keyboard = new Scanner(System.in);
System.out.println( "You have " + keychains + " keychains." );
System.out.println( "Keychains cost $10 each." );
total = cost*keychains;
System.out.println( "Total cost is $" + total + "." );
}
public static void checkout( int keychains, int cost )
{
int total;
String name;
Scanner keyboard = new Scanner(System.in);
System.out.println( "CHECKOUT" );
System.out.println();
System.out.print( "What is your name? " );
name = keyboard.next();
System.out.println( "You have " + keychains + " keychains." );
System.out.println( "Keychains cost $10 each." );
total = cost*keychains;
System.out.println( "Total cost is $" + total + "." );
System.out.println( "Thank you for your order, " + name + "!" );
}
}
Picture of the output