In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to use java to achieve supermarket commodity inventory management platform, I hope you will gain something after reading this article, let's discuss it together!
The details are as follows
1. Complete the initialization of supermarket goods. Create items and add items to the collection
two。 Show what you can do when you come to the supermarket, that is, display the main menu
3. Execute the corresponding function according to the received function option
3.1. Inventory goods inquiry 3.2. Add new products 3.3. Delete item 3.4. Modify commodity 3.5. Exit the system and end the operation of the main method
4. Loop, back to 2. Show main menu
Take adding fruit as an example: encapsulating commodity information and writing FruitItem.java files
Public class FruitItem {int ID; / / ID String name; of the commodity / / name of the commodity double price; / / unit price of the commodity}
Write market.java to complete the function:
Public class market {public static void main (String [] args) {System.out.println ("= system start! = "); ArrayList list = new ArrayList (); / / call the commodity initialization method, passing the collection init (list); while (true) {/ / print menu mainMenu (); / / function selection chooseFun (list);}} / / Commodity initialization public static void init (ArrayList list) {FruitItem item1 = new FruitItem (); item1.ID = 001; item1.name =" grapefruit "; item1.price = 5.0 FruitItem item2 = new FruitItem (); item2.ID = 002; item2.name = "Mango"; item2.price = 8.8; FruitItem item3 = new FruitItem (); item3.ID = 003; item3.name = "Orange"; item3.price = 6.6; list.add (item1); list.add (item2); list.add (item3);} / / print menu public static void mainMenu () {System.out.println ("= Welcome to the supermarket =") System.out.println ("1: query goods 2: add goods 3: delete goods 4: modify goods 5: exit");} / / function selection public static void chooseFun (ArrayList list) {Scanner sc = new Scanner (System.in); System.out.print ("enter the function of your choice:"); int choose = sc.nextInt (); switch (choose) {case 1 case / inventory query showList (list); break Case 2 list / add inventory addList (list); break; case 3 delList / delete goods delList (list); break; case 4 list / modify editList (list); break; case 5: / / exit system System.out.println ("exit system"); return; default: System.out.println ("Sorry, there is no function you entered, please re-select") Break;}} / / inventory query public static void showList (ArrayList list) {System.out.println ("= inventory list ="); System.out.println ("item number\ t commodity name\ t commodity unit price"); for (int I = 0; I < list.size (); iTunes +) {FruitItem item = list.get (I) System.out.println (item.ID + "\ t\ t" + item.name + "\ t\ t" + item.price);}} / / add inventory public static void addList (ArrayList list) {FruitItem item = new FruitItem (); Scanner sc = new Scanner (System.in); System.out.print ("Please enter commodity number:"); item.ID = sc.nextInt (); System.out.print ("Please enter commodity name:") Item.name = sc.next (); System.out.print ("Please enter commodity price:"); item.price = sc.nextDouble (); list.add (item);} / / Delete commodity public static void delList (ArrayList list) {Scanner sc = new Scanner (System.in); System.out.print ("Please enter the number of the item to be deleted"); int num = sc.nextInt (); for (int I = 0; I < list.size () FruitItem item +) {FruitItem item = list.get (I); if (item.ID = = num) {list.remove (item); return;}} System.out.println ("Sorry, there is no item of this number.") ;} / / modify merchandise public static void editList (ArrayList list) {Scanner sc = new Scanner (System.in); System.out.print ("Please enter the serial number of the item to be modified:"); int num = sc.nextInt (); for (int I = 0; I < list.size (); iTunes +) {FruitItem item = list.get (I); if (item.ID = num) {System.out.print ("Please enter a new commodity ID:") Item.ID = sc.nextInt (); System.out.print ("Please enter a new trade name:"); item.name = sc.next (); System.out.print ("Please enter a new unit price:"); item.price = sc.nextDouble (); System.out.println ("Product information updated!"); return }} System.out.println ("Sorry, there is no item with this number.") After reading this article, I believe you have a certain understanding of "how to use java to realize supermarket commodity inventory management platform". If you want to know more about it, welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.