The functions to be implemented are as follows
Package supermarket;
Import Java.util.Scanner;
Import java.util.ArrayList;
Material category
Class goods{
int id;
String name;
Double Price;
}
Main method
public class Supermarket {
public static void Main (string[] args) {
arraylist<goods> list = new arraylist<goods> ();
How to add a cargo
Addgoods (list);
Login interface
while (true) {
int number = register ();
Switch (number) {
Case 1:account (list);
Break
Case 2:add (list);
Break
Case 3:delete (list);
Break
Case 4:update (list);
Break
Case 5:return;
Case 6:system.out.println ("Enter the wrong!") ");
}
}
}
Login interface Method
public static int register () {
SYSTEM.OUT.PRINTLN ("============== welcome the Light itcast supermarket ===============");
System.out.println ("1. Cargo checklist");
System.out.println ("2. Add new cargo");
System.out.println ("3. Delete the cargo");
System.out.println ("4. Modify the cargo");
System.out.println ("5. Exit system");
Scanner sc = new Scanner (system.in);
System.out.println ("Please enter the function sequence to operate");
int choosenumber = Sc.nextint ();
return choosenumber;
}
How to put a cargo into a collection
public static void Addgoods (Arraylist<goods> list) {
Goods G1 = new Goods ();
G1.id = 9001;
G1.name = "Shaolin Cake Walnut";
g1.price=120.8;
Goods g2 = new Goods ();
G2.id = 9002;
G2.name = "Changkang cereal peony cake";
g2.price=108.6;
Goods g3 = new Goods ();
G3.id = 9003;
G3.name = "Xinjiang Origin cantaloupe";
g3.price=223.5;
List.add (G1);
List.add (G2);
List.add (G3);
}
Cargo checklist
public static void account (Arraylist<goods> list) {
System.out.println ("The cargo number name is the freight price");
for (int i=0;i<list.size (); i++) {
Goods G0 = List.get (i);
System.out.println (g0.id+ "" +g0.name+ "" +g0.price ");
}
}
Add a cargo method
public static void Add (Arraylist<goods> list) {
Scanner sc = new Scanner (system.in);
Goods g = new Goods ();
System.out.println ("Please enter the product number");
int a = Sc.nextint ();
G.id = A;
System.out.println ("Please enter the name of the product");
String B = Sc.next ();
G.name = b;
System.out.println ("Please enter the price of the goods");
Double c = sc.nextdouble ();
G.price = C;
List.add (g);
}
Delete Cargo
public static void Delete (Arraylist<goods> list) {
Scanner sc = new Scanner (system.in);
System.out.println ("Please enter the material to be removed");
int nn = Sc.nextint ();
for (int i=0;i<list.size (); i++) {
if (List.get (i). Id==nn) {
List.remove (i);
}
}
}
Modify the cargo
public static void Update (Arraylist<goods> list) {
Scanner sc = new Scanner (system.in);
System.out.println ("Please enter the material to be modified");
int num = Sc.nextint ();
for (int i=0;i<list.size (); i++) {
if (Num==list.get (i). ID) {
Goods g = new Goods ();
System.out.println ("Please enter the name of the new cargo");
String s = sc.next ();
List.get (i). Name = S;
System.out.println ("Please enter the price of the new cargo");
Double p = sc.nextdouble ();
List.get (i). price=p;
}
}
}
}
Supermarket management system written in eclipse