最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java實現(xiàn)購物管理系統(tǒng)

 更新時間:2022年05月04日 16:23:30   作者:Endless_one  
這篇文章主要為大家詳細介紹了Java實現(xiàn)購物管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Java實現(xiàn)購物管理系統(tǒng)的具體代碼,供大家參考,具體內容如下

重點內容

JAVA分支結構練習
動態(tài)數(shù)組
注冊表讀寫刪

代碼:

package Endless;

import java.util.ArrayList;
import java.util.Random;
/**
* @JAVA01.person1.java
* @author 當前用戶:Endless作者 :Endless
* @version 創(chuàng)建時間:2017年7月26日 下午6:29:16
* //實現(xiàn)商品及會員信息管理(添加,刪除,顯示)
* //實現(xiàn)超市結算
*/
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="百事可樂",ke="500ml可樂一瓶",m="5公斤面粉",ss="1個蘇泊爾炒菜鍋",o="歐萊雅爽膚水一瓶";
 static ArrayList<String>array=new ArrayList<String>();
 static Preferences goodsnodes = Preferences.systemRoot().node("goods"); //創(chuàng)建節(jié)點
 static Preferences goodschildnode = goodsnodes.node( "goods");  //創(chuàng)建子節(jié)點 

 public static void main(String []args) {


  outline();
  System.out.println("\t歡迎使用購物管理系統(tǒng)");
  System.out.println("\t1.登陸系統(tǒng)\n\t2.退出程序\n ");
  outline();
  int n =scanint(); 
  if(n == 1){ 
   login();  
  }else if( n== 2){ 
  System.out.println("已退出");
  System.exit(0);
  }else {
  System.out.println("請重新選擇:");
  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("輸入有誤,請輸入數(shù)字:");
 }
 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("輸入有誤,請輸入字符串:");
 }
 return x; 
 }
 public static void login(){
  System.out.println(" * * * * * * * * * 登陸 * * * * * * * * * * * *\n請輸入密碼\n:");
  int n1 =scanint();
  if(n1==(123123)){
  System.out.println("登陸成功\n");
  showMain();
  }else{ 
  System.out.println("密碼錯誤");
  System.out.println("請重新輸入密碼\n:");
  login();
  } 
 }
 private static void showMain() {
 System.out.println("\n\n\t歡迎使用購物管理系統(tǒng)\n"); 
 outline(); 
 System.out.println("\t\t 1. 會 員 信 息 管 理\n"); 
 System.out.println("\t\t 2. 貨 物 信 息 管 理\n"); 
 System.out.println("\t\t 3. 購 物 結 算\n"); 
 System.out.println("\t\t 4. 注 銷\n"); 
 outline(); 
 System.out.print("請選擇,輸入數(shù)字:"); 
 int n2 =scanint();
 switch (n2) {
 case 1:
  new user();
  break;
 case 2:
  goods();
  break;
 case 3:
  jiesuan();
  break;
 case 4:
  System.out.println("注銷成功");
  main(null);
 default:
  System.out.println("沒有您要的選項請重新輸入");
  showMain();
  break;
 }
 }
 private static void goods() {
 //商品管理 :添加商品: 編號 品名 價格
 // 刪除:選擇標號刪除

 outline();
 System.out.println("\t\t商品信息管理\n");
 System.out.println("\t\t1,顯示商品\n");
 System.out.println("\t\t2,添加物品\n");
 System.out.println("\t\t3,刪除商品\n");
 System.out.println("\t\t4,返回上級\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("請選擇要刪除商品的ID:\n按0返回上級");
   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("刪除成功");
    goods();
   }else if (x==0) {
    goods();
   }else {
   System.out.println("沒有此商品!"); 
    delgoods();
   }
   new user();
   } catch (Exception e) {
   System.out.println("請輸入數(shù)字");
    delgoods();
   }
 }
 private static void showgoods() {
  try {
   int leng =goodschildnode.keys().length;
   syncread();
   if(leng==0){
   System.out.println("沒有商品");
   }else{
   try {
    System.out.println("當前有"+goodschildnode.keys().length+"種商品");
    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++){
  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\t請輸入商品信息");
  System.out.println("\t\t品名,價格(元),單位");
  System.out.println("\t\t回車換行區(qū)分");
  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+" 品名:"+name+" 價格:"+price+" 單位:"+nuit);
   syncread();
   System.out.println("第"+(goodschildnode.keys().length)+"種商品添加成功");
   System.out.println("當前商品"+goodschildnode.keys().length+"種\n"+array+"\n"+array.size());
   goods(); 
  } catch (Exception e) {
   goods(); 
  }
 }
 static void jiesuan(){
 try{
  System.out.println("是否會員?是選1 否選0");
  int x= scanint();
  if (x==1){
   huiyuan = true;
   Scanner sc =new Scanner(System.in); 
   System.out.println("請輸入您的會員號:");
   int hui = sc.nextInt()/100%10;
   if(hui==9){
   System.out.println("恭喜你屬于幸運會員,可以享受全場八折優(yōu)惠");
   xhuiyuan = true;
   }else{
   xhuiyuan = false;
   }
  }else if (x==0) {
   huiyuan = false;
  }
  System.out.println("請輸入消費金額:");
  Scanner scan =new Scanner(System.in); 
  if(scan.hasNext()){
  s=scan.nextInt();
  outline();
  System.out.println("是否參加優(yōu)惠換購活動:" );
  System.out.println("1:滿50元,加2元換購"+bke );
  System.out.println("2:滿100元,加3元換購" +ke);
  System.out.println("3:滿100元,加10元換購" +m );
  System.out.println("4:滿200元,加10元換購" +ss );
  System.out.println("5:滿200元,加20元換購 " +o );
  System.out.println("0:不換購\n請選擇:\n" );
  outline();
  os();
  } 
 } catch (Exception e) {
  System.out.println("請輸入數(shù)字");
  jiesuan();

 }
 } 
 static void out(String n , double s){
 if(!(n==null)){
  System.out.println("成功換購"+n);
 }
 System.out.println("本次消費總金額:"+s+"元");
 if (huiyuan && xhuiyuan){
  System.out.println("尊敬的幸運會員,本次消費享受8折優(yōu)惠");
  double x =s*0.8;
  System.out.println("折扣為您節(jié)?。?+(s-x)+"元");
 }else if (huiyuan) {
  System.out.println("尊敬的會員,本次消費享受9折優(yōu)惠");
  double x =s*0.9;
  System.out.println("折扣為您節(jié)省:"+(s-x)+"元");
 }
 System.out.println("實際消費總金額:"+s+"元");
 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("請重新選擇");
  os();
  }
 }
 static void Err(){

  System.out.println("金額不足\n");
  main(null);
 } 
 static class user{
  static ArrayList<String>array=new ArrayList<>();
  static Preferences nodes = Preferences.systemRoot().node("user"); //創(chuàng)建節(jié)點
  static Preferences childnode = nodes.node( "user");  //創(chuàng)建子節(jié)點 


  public user() {
  outline();
  System.out.println("\t\t1,添加用戶");
  System.out.println("\t\t2,刪除用戶");
  System.out.println("\t\t3,顯示用戶");
  System.out.println("\t\t4,返回上級");
  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("沒有您要的選項!請重新選擇");
    new user();
   break;
   }
  } catch (Exception e) {
  new user();
  } 
 }
 private void deluser() throws BackingStoreException {
   System.out.println("請選擇要刪除用戶的ID:\n按0返回上級");
   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("刪除成功");
   }else if (x==0) {
   new user();
   }else {
   System.out.println("沒有此用戶!"); 
    deluser();
   }
   new user();
   } catch (Exception e) {
   System.out.println("請輸入數(shù)字");
    deluser();
   }
 }
 private static void show() {
  try {
   int leng =childnode.keys().length;
   syncread();
   if(leng==0){
   System.out.println("沒有用戶");
   }else{
   System.out.println("當前有"+childnode.keys().length+"位用戶");
   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"); //創(chuàng)建節(jié)點
  Preferences childnode = nodes.node( "user");  //創(chuàng)建子節(jié)點 
  outline();
  System.out.println("\t\t請輸入用戶信息");
  System.out.println("\t\t姓名,6位卡號,年齡,電話");
  System.out.println("\t\t回車換行區(qū)分");
  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+" 卡號:"+card+" 年齡:"+age+" 電話:"+tel);
   syncread();
   System.out.println("第"+(childnode.keys().length)+"位會員添加成功");
   System.out.println("當前用戶"+childnode.keys().length+"位\n"+array+"\n"+array.size());
   new user(); 
  } catch (Exception e) {
   new user(); 
  }
 }
 } 
}

更多學習資料請關注專題《管理系統(tǒng)開發(fā)》。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • Java基礎題新手練習(一)

    Java基礎題新手練習(一)

    下面小編就為大家?guī)硪黄狫ava基礎的幾道練習題(分享)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧,希望可以幫到你
    2021-07-07
  • Spring?Security權限注解啟動及邏輯處理使用示例

    Spring?Security權限注解啟動及邏輯處理使用示例

    這篇文章主要為大家介紹了Spring?Security權限注解啟動及邏輯處理使用示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-07-07
  • 每日六道java新手入門面試題,通往自由的道路第二天

    每日六道java新手入門面試題,通往自由的道路第二天

    這篇文章主要為大家分享了最有價值的6道java面試題,涵蓋內容全面,包括數(shù)據(jù)結構和算法相關的題目、經(jīng)典面試編程題等,對hashCode方法的設計、垃圾收集的堆和代進行剖析,感興趣的小伙伴們可以參考一下
    2021-06-06
  • Java基礎精講方法的使用

    Java基礎精講方法的使用

    方法,也稱函數(shù),如果想要重復一段或者多段代碼塊的使用,可以將這些代碼封裝成一個方法,方法具體表現(xiàn)為某種行為,使用方法可以提高代碼的復用性
    2022-05-05
  • SSH框架網(wǎng)上商城項目第27戰(zhàn)之申請域名空間和項目部署及發(fā)布

    SSH框架網(wǎng)上商城項目第27戰(zhàn)之申請域名空間和項目部署及發(fā)布

    這篇文章主要為大家詳細介紹了SSH框架網(wǎng)上商城項目第26戰(zhàn)之申請域名空間和項目部署及發(fā)布,感興趣的小伙伴們可以參考一下
    2016-06-06
  • Java高并發(fā)系統(tǒng)限流算法的實現(xiàn)

    Java高并發(fā)系統(tǒng)限流算法的實現(xiàn)

    這篇文章主要介紹了Java高并發(fā)系統(tǒng)限流算法的應用,在開發(fā)高并發(fā)系統(tǒng)時有三把利器用來保護系統(tǒng):緩存、降級和限流,限流可以認為服務降級的一種,限流是對系統(tǒng)的一種保護措施,需要的朋友可以參考下
    2022-05-05
  • 基于Nacos實現(xiàn)Spring Cloud Gateway實現(xiàn)動態(tài)路由的方法

    基于Nacos實現(xiàn)Spring Cloud Gateway實現(xiàn)動態(tài)路由的方法

    這篇文章主要介紹了基于Nacos實現(xiàn)Spring Cloud Gateway實現(xiàn)動態(tài)路由的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-06-06
  • Elasticsearch(ES)多種查詢方式案例

    Elasticsearch(ES)多種查詢方式案例

    Elasticsearch是一個分布式的RESTful搜索和分析引擎,可讓您輕松地大規(guī)模存儲,搜索和分析,這篇文章主要給大家介紹了關于Elasticsearch(ES)多種查詢方式的相關資料,需要的朋友可以參考下
    2023-09-09
  • Java使用 try-with-resources 實現(xiàn)自動關閉資源的方法

    Java使用 try-with-resources 實現(xiàn)自動關閉資源的方法

    這篇文章主要介紹了Java使用 try-with-resources 實現(xiàn)自動關閉資源的方法,本文通過示例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-06-06
  • mybatis原理概述入門教程

    mybatis原理概述入門教程

    這篇文章主要介紹了在今天這篇博文中,我將要介紹一下mybatis的框架原理,以及mybatis的入門程序,實現(xiàn)用戶的增刪改查,她有什么優(yōu)缺點以及mybatis和hibernate之間存在著怎么樣的關系,大家這些問題一起通過本文學習吧
    2016-09-09

最新評論

荆州市| 乌拉特后旗| 深水埗区| 无极县| 阿瓦提县| 扎赉特旗| 白银市| 宁德市| 盘山县| 平山县| 桂林市| 铁岭市| 那坡县| 榆林市| 云林县| 万源市| 红安县| 彭水| 日土县| 余姚市| 叶城县| 河池市| 阿拉善盟| 台北县| 武冈市| 灵寿县| 郴州市| 萨迦县| 扬州市| 景谷| 汉中市| 丽江市| 巴青县| 襄垣县| 色达县| 三明市| 云南省| 拉孜县| 岐山县| 砚山县| 石阡县|