Java Learning Note 7 (an example of a simple supermarket inventory management system)

Source: Internet
Author: User

Using the previously learned knowledge, you can simply do a supermarket inventory management system:

Define a commodity class:

 Public class Fruititem {    int  ID;    String name;     Double Price ;     int Number ;     Double Money ;}

And then:

Importjava.util.ArrayList;ImportJava.util.Scanner; Public classShop { Public Static voidMain (string[] args) {ArrayList<FruitItem> array =NewArraylist<fruititem>();        Init (array);  while(true) {mainMenu (); intChoose =choosefunction (); Switch(choose) { Case1: Showfruitlist (array);  Break;  Case2: Addfruit (array);  Break;  Case3: Deletefruit (array);  Break;  Case4: Updatefruit (array);  Break;  Case5:                return; default: System.out.println ("The number entered does not exist");  Break; }        }    }     Public Static voidUpdatefruit (arraylist<fruititem>Array) {System.out.println ("You have chosen to modify the function"); System.out.println ("Please enter the product number:"); Scanner SC=NewScanner (system.in); intID =Sc.nextint ();  for(inti = 0; I < array.size (); i++) {Fruititem Item=Array.get (i); if(item.id==ID) {System.out.println ("Please enter a new product number:"); Item.id=Sc.nextint (); System.out.println ("Please enter a new product name:"); Item.name=Sc.next (); System.out.println ("Please enter a new product price:"); Item.price=sc.nextdouble (); System.out.println ("Product Modification Successful"); return; }} System.out.println ("The number you entered does not exist"); }         Public Static voidDeletefruit (arraylist<fruititem>Array) {System.out.println ("You have selected the Delete feature"); System.out.println ("Please enter the product number:"); Scanner SC=NewScanner (system.in); intID =Sc.nextint ();  for(inti = 0; I < array.size (); i++) {Fruititem Item=Array.get (i); if(Item.id = =ID)                {Array.remove (i); System.out.println ("Delete Succeeded"); return; }} System.out.println ("The number you entered does not exist"); }         Public Static voidAddfruit (arraylist<fruititem>Array) {System.out.println ("You have chosen to add product Features"); Scanner SC=NewScanner (system.in); System.out.println ("Please enter the product number:"); intID =Sc.nextint (); System.out.println ("Please enter the name of the product:"); String name=Sc.next (); System.out.println ("Please enter the price of the product:"); DoublePrice =sc.nextdouble (); Fruititem Item=NewFruititem (); Item.id=ID; Item.name=name; Item.price=Price ;    Array.add (item); }     Public Static voidShowfruitlist (arraylist<fruititem>Array)        {System.out.println (); System.out.println ("========== Commodity inventory List =========="); System.out.println ("Product Code product name Commodity price");  for(inti = 0; I < array.size (); i++) {Fruititem Item=Array.get (i); System.out.println (Item.id+ "" + item.name + "+" +Item.price); }    }     Public Static voidInit (arraylist<fruititem>Array) {Fruititem F1=NewFruititem (); F1.id= 9527; F1.name= "Banana"; F1.price= 3.0; Fruititem F2=NewFruititem (); F2.id= 9008; F2.name= "Apple"; F2.price= 5.6; Fruititem f3=NewFruititem (); F3.id= 9879; F3.name= "Orange"; F3.price= 6.6;        Array.add (F1);        Array.add (F2);    Array.add (F3); }     Public Static voidMainMenu () {System.out.println (); System.out.println ("========== Welcome to XXX supermarket =========="); System.out.println ("1: Cargo List 2: Add goods 3: Delete Goods 4: Modify goods 5: Exit"); System.out.println ("Please enter the function number you want to operate."); }     Public Static intchoosefunction () {Scanner SC=NewScanner (system.in); returnSc.nextint (); }}

Java Learning Note 7 (an example of a simple supermarket inventory management system)

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.