Java implements the shopping management system and java shopping Management System

Source: Internet
Author: User

Java implements the shopping management system and java shopping Management System

The examples in this article share with you the specific code for implementing the shopping Management System in Java for your reference. The specific content is as follows:

Key Content

JAVA branch structure exercises
Dynamic Array
Registry read/write Deletion

Code:

Package Endless; import java. util. arrayList; import java. util. random;/*** @ JAVA01.person1. java * @ author current user: Endless author: Endless * @ version Creation Time: 6:29:16, January 1, July 26, 2017 * // manages product and member information (add, delete, and display) * // implement supermarket settlement */import java. util. imports; import java. util. prefs. backingStoreException; import java. util. prefs. preferences; public class persion {static int s; static boolean huiyuan, xhuiyuan; static String bke = "Pepsi", ke = "ML cola bottle", m = "5 kg flour", ss = "1 supor Wok", o = "l'oreal toner bottle "; static ArrayList <String> array = new ArrayList <String> (); static Preferences goodsnodes = Preferences. systemRoot (). node ("goods"); // create a node static Preferences goodschildnode = goodsnodes. node ("goods"); // create the subnode public static void main (String [] args) {outline (); System. out. println ("\ t welcome to the shopping management System"); System. out. println ("\ t1. login System \ n \ t2. exit program \ n"); outline (); I Nt 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 {partition scan = new partition (System. in); x = scan. nextInt ();} catch (Exception e) {System. out. print Ln ("incorrect input; enter a number:") ;}return x ;}public static String scanStr () {String x = null; try {scan = new partition (System. in); x = scan. next ();} catch (Exception e) {System. out. println ("incorrect input. Please enter the string:") ;}return x ;}public static void login () {System. out. println ("********************** \ n enter the password \ n :"); int n1 = scanint (); if (n1 = (123123) {System. out. println ("Login successful \ n"); showMain ();} Else {System. out. println ("Incorrect password"); System. out. println ("enter the password again \ n:"); login () ;}} private static void showMain () {System. out. println ("\ n \ t welcome to the shopping Management System \ n"); outline (); System. out. println ("\ t 1. member Information Management \ n "); System. out. println ("\ t 2. cargo Information Management \ n "); System. out. println ("\ t 3. transaction calculation \ n "); System. out. println ("\ t 4. note sales \ n "); outline (); System. out. print ("select, enter a number:"); int n2 = scanint (); Switch (n2) {case 1: new user (); break; case 2: goods (); break; case 3: jiesuan (); break; case 4: System. out. println ("logout successful"); main (null); default: System. out. println ("do not have the option you want, Please re-enter"); showMain (); break;} private static void goods () {// item management: Add item: number product name Price // Delete: select a number to delete outline (); System. out. println ("\ t commodity information management \ n"); System. out. println ("\ t \ t1, display item \ n"); System. out. println ("\ t \ t2, add item \ n"); System. o Ut. println ("\ t \ t3, delete item \ n"); System. out. println ("\ t \ t4, return upper \ 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 ("select the ID of the product to be deleted: \ n return to the upper level by 0"); try {shortscan = new partition (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 ("deleted successfully"); goods ();} else if (x = 0) {goods ();} else {System. out. println ("This item is not available! "); Delgoods ();} new user ();} catch (Exception e) {System. out. println ("enter a number"); delgoods () ;}} private static void showgoods () {try {int leng = goodschildnode. keys (). length; syncread (); if (leng = 0) {System. out. println ("no product");} else {try {System. out. println ("currently available" + goodschildnode. keys (). length + "commodity"); for (int I = 0; I <= goodschildnode. keys (). length; I ++) {String shows = goodschildnode. get (array. get (I), ""); System. out. println (shows); System. out. println ("── ─");} System. out. println ("00000000");} catch (Exception e) {}} catch (BackingStoreException e) {} System. out. println ("111111111"); goods ();} private static void syncread () {try {String [] arr = goodschildnode. keys (); goodschildnode. sync (); array. clear (); for (int I = 0; I <arr. length; I ++) {arra Y. 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 enter product information"); System. out. println ("\ t name, price (yuan), unit"); System. out. println ("\ t carriage return line breaks"); 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 ("Number" + (goodschildnode. keys (). length) + "products added successfully"); System. out. println ("current product" + goodschildnode. keys (). length + "Type \ n" + array + "\ n" + array. size (); goods ();} Catch (Exception e) {goods () ;}} static void jiesuan () {try {System. out. println ("Is it a member? Yes select 1 no select 0 "); int x = scanint (); if (x = 1) {huiyuan = true; then SC = new then (System. in); System. out. println ("Enter your membership number:"); int hui = SC. nextInt ()/100% 10; if (hui = 9) {System. out. println ("Congratulations, you are a lucky member and can enjoy a discount"); xhuiyuan = true;} else {xhuiyuan = false;} else if (x = 0) {huiyuan = false;} System. out. println ("Enter the consumption amount:"); scanned scan = new partition (System. in); if (scan. hasNext () {s = scan. nextInt (); Outline (); System. out. println ("whether to participate in the discount redemption activity:"); System. out. println ("1: 50 yuan, plus 2 yuan for purchase" + bke); System. out. println ("2: over 100 yuan, plus 3 yuan for purchase" + ke); System. out. println ("3: over 100 yuan, plus 10 yuan for purchase" + m); System. out. println ("4: over 200 yuan, plus 10 yuan for purchase" + ss); System. out. println ("5: over 200 yuan, plus 20 yuan for purchase" + o); System. out. println ("0: Do not exchange \ n please select: \ n"); outline (); OS () ;}} catch (Exception e) {System. out. println ("enter a number"); jiesuan () ;}} static void out (St Ring n, double s) {if (! (N = null) {System. out. println ("successful purchase" + n);} System. out. println ("total consumption amount:" + s + "Yuan"); if (huiyuan & xhuiyuan) {System. out. println ("Dear lucky Member, enjoy a 0.8 discount for this purchase"); double x = s *; System. out. println ("discounts save you money:" + (s-x) + "Yuan");} else if (huiyuan) {System. out. println ("Dear member, enjoy a 0.9 discount for this purchase"); double x = s *; System. out. println ("savings:" + (s-x) + "RMB");} System. out. println ("total actual consumption amount:" + s + ""); showMain ();} static void OS () {sw Itch (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 a node static Preferences childnode = nodes. node ("user"); // create a subnode public user () {outline (); System. out. println ("\ t \ t1, add user"); System. out. println ("\ t \ t2, delete user"); System. out. println ("\ t \ t3, show user"); System. out. println ("\ t \ t4, return upper-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 options you want! Please reselect "); new user (); break;} catch (Exception e) {new user () ;}} private void deluser () throws BackingStoreException {System. out. println ("select the ID of the user to be deleted: \ n return to the upper level by 0"); try {shortscan = new Queue (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); S Ystem. out. println ("deleted successfully");} else if (x = 0) {new user ();} else {System. out. println ("No such user! "); Deluser ();} new user ();} catch (Exception e) {System. out. println ("enter a number"); deluser () ;}} private static void show () {try {int leng = childnode. keys (). length; syncread (); if (leng = 0) {System. out. println ("no user");} else {System. out. println ("current" + 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 ("── ─") ;}} catch (BackingStoreException e) {} new user ();} private static void syncread () {try {String [] arr = childnode. keys (); childnode. sync (); array. clear (); for (int I = 0; I <arr. length; I ++) {array. add (arr [I]) ;}} catch (Exception e) {}} private static void add () {Preferences nodes = Preferences. systemRoot (). node ("user"); // create a node Preferences childnode = nodes. node ("user"); // create the child node outline (); System. out. println ("\ t enter user information"); System. out. println ("\ t name, 6-digit card number, age, phone number"); System. out. println ("\ t carriage return line breaks"); 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 + "tel:" + tel ); syncread (); System. out. println ("nth" + (childnode. keys (). length) + "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 information, see management system development.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

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.