Java study note 7 (simple supermarket inventory management system example ),

Source: Internet
Author: User

Java study note 7 (simple supermarket inventory management system example ),

With the previous knowledge, you can simply build a supermarket inventory management system:

Define a product category:

public class FruitItem {    int ID;    String name;    double price;    int number;    double money;}

Then:

Import java. util. arrayList; import java. util. extends; public class Shop {public static void main (String [] args) {ArrayList <FruitItem> array = new ArrayList <FruitItem> (); init (array); while (true) {mainMenu (); int choose = chooseFunction (); switch (choose) {case 1: showFruitList (array); break; case 2: addFruit (array); break; case 3: deleteFruit (array); break; case 4: updateFruit (array); break; case 5: return; default: System. out. println ("the Input Serial number does not exist"); break ;}} public static void updateFruit (ArrayList <FruitItem> array) {System. out. println ("You selected the modify function"); System. out. println ("Enter the product number:"); then SC = new then (System. in); int ID = SC. nextInt (); for (int I = 0; I <array. size (); I ++) {FruitItem item = array. get (I); if (item. ID = ID) {System. out. println ("Enter the new product number:"); item. ID = SC. nextInt (); System. out. println ("Enter the new product name:"); item. name = SC. next (); System. out. println ("Enter the new product price:"); item. price = SC. nextDouble (); System. out. println ("item modified successfully"); return ;}} System. out. println ("the number you entered does not exist");} public static void deleteFruit (ArrayList <FruitItem> array) {System. out. println ("delete function selected"); System. out. println ("Enter the product number:"); then SC = new then (System. in); int ID = SC. nextInt (); for (int I = 0; I <array. size (); I ++) {FruitItem item = array. get (I); if (item. ID = ID) {array. remove (I); System. out. println ("deleted successfully"); return ;}} System. out. println ("the number you entered does not exist");} public static void addFruit (ArrayList <FruitItem> array) {System. out. println ("You selected the add product feature"); optional SC = new feature (System. in); System. out. println ("Enter the product number:"); int ID = SC. nextInt (); System. out. println ("Enter the product name:"); String name = SC. next (); System. out. println ("Enter the unit price of the product:"); double price = SC. nextDouble (); FruitItem item = new FruitItem (); item. ID = ID; item. name = name; item. price = price; array. add (item);} public static void showFruitList (ArrayList <FruitItem> array) {System. out. println (); System. out. println ("=========== commodity inventory list ==========="); System. out. println ("Product ID product name product price"); for (int I = 0; I <array. size (); I ++) {FruitItem item = array. get (I); System. out. println (item. ID + "" + item. name + "" + item. price) ;}} public static void init (ArrayList <FruitItem> array) {FruitItem f1 = new FruitItem (); f1.ID = 9527; f1.name = "banana"; f1.price = 3.0; fruitItem f2 = new FruitItem (); f2.ID = 9008; f2.name = "apple"; f2.price = 5.6; FruitItem f3 = new FruitItem (); f3.ID = 9879; f3.name = "orange "; f3.price = 6.6; array. add (f1); array. add (f2); array. add (f3);} public static void mainMenu () {System. out. println (); System. out. println ("=========== welcome to a certain supermarket =========="); System. out. println ("1: Goods List 2: Add goods 3: delete goods 4: Modify Goods 5: Exit"); System. out. println ("Enter the function serial number you want to operate");} public static int chooseFunction () {feature SC = new feature (System. in); return SC. nextInt ();}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.