l watch list later, it may be a list divided into three parts (top of list, the list in section, a list of the bottom portion)
l 1. Listing top fixed data, direct printing can
l 2. Listing in the commodity unit, the data changes, product information needs to be recorded, printing
Through observation, we should determine a product has the following attributes:
Brand Model : - title, String type
Size: size of the article, Double Type
Price: Price items, Double Type
Configuration: this one is the configuration information for each product, String type
Inventory: this one is the number of inventories of each commodity, int type
l 3. Listing bottom portion comprises a statistical operation, the need has been calculated, the printing
We found two separate amount may vary
Total stock: the total number of all goods, int type
Stock Amount: the amount of all commodities, Double Type
import java.util.Scanner; import java.util.ArrayList; public class Menu { public static void main(String[] args) { Scanner sc=new Scanner(System.in); ArrayList<Goods> list=new ArrayList<Goods>(); while(true){ mainMenu(); int choose=sc.nextInt(); switch(choose){ case 1: // 货物清单 getGoods (List); BREAK ; Case 2 : deleteGoods (List); BREAK ; Case . 3 : // add goods addGoods (List); BREAK ; Case . 4 : updateGoods (List); BREAK ; Case . 5 : return ; default : the System. out.println ( "you make a mistake, re-enter" ); BREAK ; } } } 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. modify goods " ); System.out.println ( "5. exit" ); System.out.println ( "Please enter your choice" ); } public static void addGoods(ArrayList<Goods>List) { System.out.println ( "Please enter a new number of fruits" ); Scanner SC = new new Scanner (the System.in); int GID = sc.nextInt (); System.out.println ( "Please enter a new fruit the name " ); String gname = sc.next (); System.out.println ( " Please enter the new price of fruit " ); Double prize = sc.nextDouble (); // it attributes to the package object commodity goods goods = new new Goods (); goods.gid = GID; goods.gname = gname; goods.prise= Prize; // objects stored set List.add (Goods); } public static void getGoods (the ArrayList <Goods> List) { System.out.println ( "product inventory ===== ===== === " ); 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) .prise); } } public static void updateGoods (the ArrayList <Goods> List) { 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 your want to modify trade name " ); String gname = sc.next (); System.out.println ( " Please enter your want to modify commodity price " ); Double prize = sc.nextDouble (); for ( int i = 0; i <list.size (); I ++ ) { IF (List.get (I) == .gid GID) { List.get (I) .gname = gname; List.get (I) .prise=prise; } } } public static void deleteGoods(ArrayList<Goods> list){ getGoods(list); System.out.println(""); Scanner sc=new Scanner(System.in); int gid=sc.nextInt(); for(int i=0;i<list.size();i++){ if(list.get(i).gid==gid){ list.remove(i); } } } }
Print results: