I wrote this program to implement a shopping cart. It supports adding/removing items to the cart, viewing the current order, and completing the checkout process.
import java.util.Scanner;
public class Keychains1 {
public static Scanner keyboard = new Scanner(System.in);
public static boolean stay = true;
public static void add_keychains() {
System.out.println("ADD KEYCHAINS");
}
public static void remove_keychains() {
System.out.println("REMOVE KEYCHAINS");
}
public static void view_order() {
System.out.println("VIEW ORDER");
}
public static void checkout() {
System.out.println("CHECKOUT");
stay = false;
}
public static void main(String[] args) {
int choice;
while (stay) {
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.println();
System.out.print("Please enter your choice: ");
choice = keyboard.nextInt();
System.out.println();
if (choice == 1) {
add_keychains();
}
else if (choice == 2) {
remove_keychains();
}
else if (choice == 3) {
view_order();
}
else if (choice == 4) {
checkout();
}
else {
System.out.println("Error. Please choose again.");
}
System.out.println();
}
}
}