Assignemnt #101
Code
/// Name: Daniel Nguyen
/// Period: 6
/// Project Name: KeyCh
/// File Name: KeyCh.java
/// Date: 3/11/2015
import java.util.Scanner;
import java.util.Scanner;
import java.util.InputMismatchException;
public class KeyCh
{
public static void main( String[] args )
{
System.out.println("Welcome to the keychain store!!!\n");
int choice = 0;
do
{
showMenu();
do choice = askChoice();
while (choice==0);
if (choice == 1) addKey();
if (choice == 2) removeKey();
if (choice == 3) viewOrder();
}
while (choice!=4);
checkout();
}
public static void showMenu()
{
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\n");
}
public static int askChoice()
{
Scanner keyboard = new Scanner(System.in);
int choice = 0;
System.out.print("Enter your choice: ");
try
{
choice = keyboard.nextInt();
}
catch (InputMismatchException e)
{
choice = 0;
System.out.println("WRONG INPUT!!!\n");
}
if (choice < 1 || choice > 4) choice = 0;
return choice;
}
public static void addKey()
{
System.out.println("\nADD KEYCHAINS\n");
}
public static void removeKey()
{
System.out.println("\nREMOVE KEYCHAINS\n");
}
public static void viewOrder()
{
System.out.println("\nVIEW ORDER\n");
}
public static void checkout()
{
System.out.println("\nCHECKOUT\n");
}
}
Picture of the output