Supermarkets, stock management

com.oracle.demo02 Package;

Import of java.util.ArrayList;
Import java.util.Scanner;

public class Menu {
    public static void main (String [] args) {
        Scanner Scanner new new SC = (the System.in);
        the ArrayList <Goods > = new new List the ArrayList <Goods> ();
        the while (to true) {
            the mainMenu ();
            // let the user input selecting
            int = sc.nextInt the choose ();
            // a user's selection determines
            Switch (the choose) {
            Case. 1 :
                // list of goods
                getGoods (list);
                BREAK;
            Case 2:
                // delete cargo
                deleteGoods (list);
                BREAK;
            Case 3:
                addGoods (List);
                BREAK;
            Case 4:
                // modified cargo
                updateGoods (List);
                BREAK;
            Case 5:
                return;
            default:
                System.out.println ( "Your input is incorrect, please re-enter" );
                BREAK;
            }
        }
    }

    // main menu page
    public static void mainMenu () {
        System.out.println ( "Welcome to Oracle supermarket ========= ========");
        System.out.println ( "1 list of goods.");
        System.out.println ( "2 delete the goods.");
        System.out.println ( "3.Add goods ");
        System.out.println ( "4 modified goods.");
        System.out.println (. "5 Exit");
        System.out.println ( "Please enter your choice");
    }

    // add cargo
    public static void addGoods (the ArrayList <Goods> List) {
        System.out.println ( "Please enter the number of the new fruit:");
        Scanner Scanner new new SC = (the System.in);
        int sc.nextInt GID = ();
        the System.out. println ( "Please enter the name of the new fruit");
        String gname = sc.next ();
        System.out.println ( "Please enter the new price of fruit");
        Double. price = sc.nextDouble ();
        // the property product encapsulated object
        goods goods goods new new = ();
        goods.gid = GID;
        goods.gname = gname;
        goods.price =. price;
        // objects into the collection
        List.add (Goods);
    }
    public static void getGoods (the ArrayList <Goods> List) {
        System.out.println ( "product inventory ====== =======");
        the System.out. println ( "product Code \ t trade name \ t commodity price");
        for (int I = 0; I <list.size (); I ++) {
            System.out.println (List.get (I) .gid + "\ T "
                    + List.get (I) .gname +" \ T "+ List.get (I) .price);            
        }        
    }
    // the modified pages
    public static void updateGoods (the ArrayList <Goods> List) {
        // show the user what all goods
        getGoods (List);
        System.out.println ( "Please enter the number you want to modify product");
        Scanner sc = new new Scanner (System.in);
        int gid = sc.nextInt ();
        System.out.println ( "Please enter the name you want to modify product");
        String gname = sc.next ();
        System.out.println ( "Please enter the price you want to modify product");
        Double. Price = sc.nextDouble ();
        for (int I = 0; I <list.size (); I ++) {
            // find the gid of the user input corresponding to the object
            if (list.get (i) .gid == gid) {
                List.get (I) = .gname gname;
                List.get (I) =. price .price;
            }
        }        
    }
    // remove pages
    public static void deleteGoods (the ArrayList <goods> List) {
        // show the user all goods
        getGoods (list );
        System.out.println ( "Please enter the article number you want to delete");
        Scanner sc = new new Scanner (System.in);
        int gid = sc.nextInt ();
        // find gid user input corresponding to the object goods
        for (int I = 0; I <list.size (); I ++) {
            IF (List.get (I) .gid == gid) {
                // delete item objects
                list.remove (I);
                
            }
            
        }
        
    }
}

Guess you like

Origin www.cnblogs.com/G-qz/p/10958778.html