This article shares the specific code of Java implementation of shopping management system for your reference. The specific content is as follows
Key content
JAVA branch structure exercise dynamic array registry reading, writing and deletion
Code:
package Endless;import java.util.ArrayList;import java.util.Random;/*** @JAVA01.person1.java* @author Current user: Endless Author:Endless* @version Created time: July 26, 2017 at 6:29:16 pm* //Implement product and member information management (add, delete, display)* //Implement supermarket settlement*/import java.util.Scanner;import java.util.prefs.BackingStoreException;import java.util.prefs.Preferences;public class persion { static int s; static boolean huiyuan,xhuiyuan; static String bke="Pepsi Cola",ke="500ml Cola bottle",m="5 kg of flour",ss="1 Supor stir-frying pan",o="L'Oreal toner bottle"; static ArrayList<String>array=new ArrayList<String>(); static Preferences goodsnodes = Preferences.systemRoot().node("goods"); //Create node static Preferences goodschildnode = goodsnodes.node( "goods"); //Create child node public static void main(String []args) { outline(); System.out.println("/tWelcome to use Shopping Management System"); System.out.println("/t1.Login System/n/t2.Exit Program/n "); outline(); int n =scanint(); if(n == 1){ login(); }else if( n== 2){ System.out.println("Exited"); System.exit(0); }else { System.out.println("Please reselect:"); main(null); } } public static void outline(){ System.out.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /n"); } public static int scanint(){ int x = 0; try { Scanner scan =new Scanner(System.in); x = scan.nextInt(); } catch (Exception e) { System.out.println("Input is incorrect, please enter the number: "); } return x; } public static String scanStr(){ String x = null; try { Scanner scan =new Scanner(System.in); x = scan.next(); } catch (Exception e) { System.out.println("Input is incorrect, please enter the string: "); } return x; } public static void login(){ System.out.println(" * * * * * * * * * * * * * * * * * * * * * * * * * * /nPlease enter the password/n: "); int n1 =scanint(); if(n1==(123123)){ System.out.println("Login successfully/n"); showMain(); }else{ System.out.println("Password error"); System.out.println("Please re-enter the password/n:"); login(); } } private static void showMain() { System.out.println("/n/n/t Welcome to use the shopping management system/n"); outline(); System.out.println("/t/t 1. Member Information Management/n"); System.out.println("/t/t 2. Goods Information Management/n"); System.out.println("/t/t 3. Shopping Settlement/n"); System.out.println("/t/t 4. Log out/n"); outline(); System.out.print("Please select, enter the number:"); int n2 =scanint(); switch (n2) { case 1: new user(); break; case 2: goods(); break; case 3: jiesuan(); break; case 4: System.out.println("Log out successfully"); main(null); default: System.out.println("Re-enter the option you want"); showMain(); break; } } private static void goods() { //Product management: Add products: Numbered product name price//Delete: Select the label to delete outline(); System.out.println("/t/t product information management/n"); System.out.println("/t/t1, display product/n"); System.out.println("/t/t2, add item/n"); System.out.println("/t/t3, delete product/n"); System.out.println("/t/t4, return to previous/n"); outline(); int n = scanint(); if (n==1){ showgoods(); }else if(n==2){ addgoods(); }else if(n ==3){ delgoods(); }else if(n==4) { showMain(); }else { goods(); } } private static void delgoods() { System.out.println("Please select the ID of the product to be deleted: /n Press 0 to return to the previous level"); try { Scanner scan =new Scanner(System.in); int x = scan.nextInt(); boolean remove=false; for (int i=0;i<array.size();i++){ if(x==Integer.parseInt(array.get(i))){ remove=true; } } if (remove){ goodschildnode.remove(Integer.toString(x)); System.out.println("Delete successfully"); goods(); }else if (x==0) { goods(); }else { System.out.println("No this product!"); delgoods(); } new user(); } catch (Exception e) { System.out.println("Please enter a number"); delgoods(); } } private static void showgoods() { try { int length =goodschildnode.keys().length; syncread(); if(leng==0){ System.out.println("No product"); }else{ try { System.out.println("Currently there is"+goodschildnode.keys().length+"product"); for(int i = 0;i<=goodschildnode.keys().length;i++){ String shows =goodschildnode.get(array.get(i), ""); System.out.println(shows); System.out.println("───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────� goodschildnode.sync(); array.clear(); for(int i=0;i<arr.length;i++){ array.add(arr[i]); } } catch (Exception e) { } } private static int check(int x) { Random n=new Random(); syncread(); for(int i=0;i<array.size();i++){ if(x==Integer.parseInt(array.get(i))){ check(n.nextInt(999)+1); } } return x; } private static void addgoods(){ outline(); System.out.println("/t/tPlease enter product information"); System.out.println("/t/t product name, price (yuan), unit"); System.out.println("/t/t carriage return line break distinction"); outline(); syncread(); String name =scanStr(); String nuit =scanStr(); int price = scanint(); Random n=new Random(); String id ; id=Integer.toString(check(n.nextInt(999)+1)); try{ goodschildnode.put(id, "ID:"+id+" Product name: "+name+" Price: "+price+" Unit: "+nuit); syncread(); System.out.println("Things"+(goodschildnode.keys().length)+"Series added successfully"); System.out.println("Current product"+goodschildnode.keys().length+"Series/n"+array+"/n"+array.size()); goods(); } catch (Exception e) { goods(); } } static void jiesuan(){ try{ System.out.println("Is it a member? Is it a member? Choose 1 No select 0"); int x= scanint(); if (x==1){ huiyuan = true; Scanner sc =new Scanner(System.in); System.out.println("Please enter your membership number: "); int hui = sc.nextInt()/100%10; if(hui==9){ System.out.println("Congratulations on being a lucky member, you can enjoy a 20% discount on the whole venue"); xhuiyuan = true; }else{ xhuiyuan = false; } }else if (x==0) { huiyuan = false; } System.out.println("Please enter the consumption amount:"); Scanner scan =new Scanner(System.in); if(scan.hasNext()){ s=scan.nextInt(); outline(); System.out.println("Where to participate in the discount purchase activity:" ); System.out.println("1: add 2 yuan for purchases over 50 yuan, add 2 yuan for purchases over 50 yuan" +bke ); System.out.println("2: add 3 yuan for purchases over 100 yuan" +ke); System.out.println("3: add 10 yuan for purchases over 10 yuan for purchases over 10 yuan" +m ); System.out.println("4: Over 200 yuan, add 10 yuan to exchange" +ss); System.out.println("5: Over 200 yuan, add 20 yuan to exchange" +o); System.out.println("0: Not over 200 yuan, please select: /n" ); outline(); os(); } } catch (Exception e) { System.out.println("Please enter number"); jiesuan(); } } static void out(String n, double s){ if(!(n==null)){ System.out.println("Successfully exchanged" +n); } System.out.println("Total amount of this consumption: "+s+"yuan"); if (huiyuan && xhuiyuan){ System.out.println("Dear lucky members, enjoy 20% off for this consumption"); double x =s*0.8; System.out.println("Discount saves you: "+(sx)+"yuan"); }else if (huiyuan) { System.out.println("Dear members, enjoy 10% off for this consumption"); double x =s*0.9; System.out.println("Discount saves you: "+(sx)+"yuan"); } System.out.println("The total actual consumption amount: "+s+"yuan"); showMain(); } static void os(){ switch (scanint()) { case 0: out(null,s); case 1: if(s>=52){ out(bke,s+2); }else{ Err(); } case 2: if(s>=103){ out(ke,s+3); }else{ Err(); } break; case 3: if(s>=110){ out(m,s+10); }else{ Err(); } break; case 4: if(s>=210){ out(ss,s+10); }else{ Err(); } break; case 5: if(s>=220){ out(o,s+20); }else{ Err(); } break; default: System.out.println("Please reselect"); os(); } } static void Err(){ System.out.println("Insufficient amount/n"); main(null); } static class user{ static ArrayList<String>array=new ArrayList<>(); static Preferences nodes = Preferences.systemRoot().node("user"); //Create node static Preferences childnode = nodes.node( "user"); //Create child node public user() { outline(); System.out.println("/t/t1,add user"); System.out.println("/t/t2, delete user"); System.out.println("/t/t3, display user"); System.out.println("/t/t4, return to previous level"); outline(); try { int x=scanint(); switch (x) { case 1: add(); break; case 2: deluser(); break; case 3: show(); break; case 4: showMain(); break; default: System.out.println("No option you want! Please reselect"); new user(); break; } } catch (Exception e) { new user(); } } private void deluser() throws BackingStoreException { System.out.println("Please select the ID of the user to be deleted: /n Press 0 to return to the previous level"); try { Scanner scan =new Scanner(System.in); int x = scan.nextInt(); boolean remove=false; for (int i=0;i<array.size();i++){ if(x==Integer.parseInt(array.get(i))){ remove=true; } } if (remove){ childnode.remove(Integer.toString(x)); System.out.println("Delete successfully"); }else if (x==0) { new user(); }else { System.out.println("No this user!"); deluser(); } new user(); } catch (Exception e) { System.out.println("Please enter a number"); deluser(); } } private static void show() { try { int length =childnode.keys().length; syncread(); if(leng==0){ System.out.println("No user"); }else{ System.out.println("Currently there is"+childnode.keys().length+"bit user"); for(int i = 0;i<=childnode.keys().length;i++){ String shows =childnode.get(childnode.keys()[i], ""); System.out.println(shows); System.out.println("───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────� (Exception e) { } } private static void add(){ Preferences nodes = Preferences.systemRoot().node("user"); //Create node Preferences childnode = nodes.node( "user"); //Create child node outline(); System.out.println("/t/tPlease enter user information"); System.out.println("/t/t Name, 6-digit card number, age, phone number"); System.out.println("/t/t Enter line breaking distinction"); outline(); syncread(); String name =scanStr(); int card = scanint(); int age =scanint(); String tel =scanStr(); Random n=new Random(); String id ; id = Integer.toString(n.nextInt(999)+1); try{ childnode.put(id, "ID:"+id+" Name: "+name+" Card number: "+card+" Age: "+age+" Phone: "+tel); syncread(); System.out.println("Th"+(childnode.keys().length)+"Bit member added successfully"); System.out.println("Current User"+childnode.keys().length+"bit/n"+array+"/n"+array.size()); new user(); } catch (Exception e) { new user(); } } } }For more learning materials, please pay attention to the special topic "Management System Development".
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.