Hello, i need to get this shopping cart to work and i need help at creating a place to save the data after the "Enter product move".
This is the code so far. I need this step to move on with delete, update, search
Thanks in advance!
import java.util.Scanner;
public class Shoppingcart {
private static Scanner scanner = new Scanner(System.in);
private static String[] menuItems
= { "Exit", "Insert Item", "Update Item", "Search Item", "Delete Item"
};
private static Products productList;
private static String item;
static void printMenu() {
int i = 0;
for (String item : menuItems) {
System.out.printf("%d -> %s\n", i, item);
i++;
}
}
static int requestAction() {
int choice = 0;
printMenu();
do {
System.out.print("Choose a number from the menu: ");
if (scanner.hasNextInt())
choice = scanner.nextInt();
scanner.nextLine(); //
} while (choice < 0 || choice >= menuItems.length);
return choice;
}
public static void main (String[] args){
int test;
do {
test = requestAction();
commander(test);
} while (test != 0);
System.out.println("Exit from the app"); //
}
private static void commander(int n) {
switch (n) {
case 1: insertItem();
break;
// case 2: updateitem();
// break;
// case 3: searchitem();
// break;
// case 4: deleteitem();
}
}
static void insertItem() {
System.out.print("Enter product: ");
String item = scanner.nextLine();
System.out.println(item);
}
public class Products {
private String[] [] items = new String[50][1];
private int nextAvail = 0;
public void insertItem(String[] item) {
items[nextAvail] = item;
nextAvail++;
}
public boolean isFull() {
return (nextAvail >= items.length);
}
}
public int findProduct(String item) {
Object[] products = null;
int nextAvail = 0;
for (int i = 0; i < nextAvail; i++)
if (products[i].equals(item) )
return i;
return -1;
}