java實(shí)現(xiàn)鮮花銷售系統(tǒng)
本文實(shí)例為大家分享了java實(shí)現(xiàn)鮮花銷售系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
一、練習(xí)目標(biāo)
1.體會數(shù)組的作用
2.找到分層開發(fā)的感覺
3.收獲分層開發(fā)的興趣
4.作出效果,找到自信
5.學(xué)會調(diào)試錯(cuò)誤
6.掌握數(shù)組的增刪改查方法
二、項(xiàng)目需求
1.使用分層開發(fā):表示層(測試類)、業(yè)務(wù)層(鮮花管理類)、實(shí)體層(鮮花類)
2.使用數(shù)組的相關(guān)方法實(shí)現(xiàn)鮮花銷售系統(tǒng)的查詢訂單、修改訂單、刪除訂單功能。
3.查詢訂單之前需要對數(shù)組進(jìn)行初始化操作
4.修改訂單時(shí),需要先判斷訂單是否存在,存在才可以修改,修改后可以選擇是否保存修改,若保存修改,顯示修改后的訂單信息
5.刪除訂單時(shí),需要先判斷訂單是否存在,存在才可刪除,詢問用戶是否確認(rèn)刪除,確認(rèn)后再刪除訂單信息,刪除成功后,顯示目前最新的訂單信息
三、提供的素材
1.項(xiàng)目運(yùn)行效果圖
四、實(shí)施步驟
1.教師運(yùn)行項(xiàng)目,學(xué)生熟悉項(xiàng)目功能
2.教師講解基本代碼思路
3.給學(xué)生提供運(yùn)行效果截圖
4.學(xué)生根據(jù)截圖實(shí)現(xiàn)效果
5.教室講解編寫代碼步驟
6.期間穿插已完成學(xué)生展示效果
五、編寫代碼步驟
1.定義鮮花類Flower,放入實(shí)體層
2.定義鮮花管理類FlowerMgr,通過一個(gè)數(shù)組實(shí)現(xiàn)對鮮花的管理,放入業(yè)務(wù)層。
3.FlowerMgr類中,實(shí)現(xiàn)public void inital(){}方法,用于完成對鮮花管理系統(tǒng)的初始化功能(數(shù)組的初始化)
4.FlowerMgr類中,實(shí)現(xiàn)public void mainMenu(){}方法,用于完成功能面板的展示及功能選擇
5.FlowerMgr類中,實(shí)現(xiàn)private void searchAll(){}方法,用于完成查詢訂單的功能
6.FlowerMgr類中,實(shí)現(xiàn)private void updateSale(){}方法,用于完成修改訂單的功能
7.FlowerMgr類中,實(shí)現(xiàn)private void deleteSale(){}方法,用于完成刪除訂單的功能
8.定義測試類Test,放入表示層;在測試類中,先初始化鮮花管理系統(tǒng),然后調(diào)用mainMenu()方法,實(shí)現(xiàn)具體功能
9.編寫代碼過程中,盡量每完成一個(gè)功能,就對其進(jìn)行測試
六、學(xué)生擴(kuò)展
1.學(xué)生嘗試增加鮮花管理系統(tǒng)的功能:
a)增加新增訂單功能
b)在學(xué)習(xí)異常處理后,可進(jìn)行必要的異常處理
2.完善功能代碼:
a)銷售數(shù)量不能為負(fù)數(shù)
b)鮮花價(jià)格不能為負(fù)數(shù)
public class Flower { private int number; private String name; private int count; private double price; private String date; private String saler; public Flower(int number, String name, int count, double price, String date, String saler) { super(); this.number = number; this.name = name; this.count = count; this.price = price; this.date = date; this.saler = saler; } public Flower() { super(); // TODO Auto-generated constructor stub } public int getNumber() { return number; } public void setNumber(int number) { this.number = number; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getCount() { return count; } public void setCount(int count) { this.count = count; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public String getDate() { return date; } public void setDate(String date) { this.date = date; } public String getSaler() { return saler; } public void setSaler(String saler) { this.saler = saler; } }
import java.util.*; import java.util.Scanner; public class FlowerMgr { Scanner input1=new Scanner(System.in); static Flower[] flower=new Flower[5]; //public void inital(){ //初始化,花的數(shù)組 static{ flower[0]=new Flower(1001,"香檳玫瑰",10,318.0,"2018-12-12","王二"); flower[1]=new Flower(1002,"白玫瑰",99,538.0,"2018-2-2","張星宇"); flower[2]=new Flower(1003,"紫色桔梗",40,123.0,"2018-12-16","王二"); flower[3]=new Flower(1004,"粉色百合",120,188.0,"2016-12-11","王二"); flower[4]=new Flower(1005,"無聲的愛",1000,219.0,"2016-12-15","張星宇"); } //完成功能面板的展示功能 public void mainMenu(){ System.out.println("~~~~~~~~~~歡迎光臨鮮花管理系統(tǒng)~~~~~~~~~~~"); System.out.println("\t1.查詢銷售訂單"); System.out.println("\t2.修改銷售訂單"); System.out.println("\t3.刪除銷售訂單"); System.out.println("\t4.系統(tǒng)退出"); System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); } //查詢訂單功能 public void searchAll(){ System.out.println("這里是全部的訂單"); System.out.println("編號\t鮮花名稱\t銷售數(shù)量\t價(jià)格\t銷售日期\t\t銷售員"); for(int i=0;i<flower.length;i++){ **if(flower[i]!=null)**{ Flower f=flower[i]; System.out.println(f.getNumber()+"\t"+f.getName()+"\t"+f.getCount()+"\t" +f.getPrice()+"\t" +f.getDate()+"\t"+f.getSaler()); } } } //修改訂單功能 public void updateSale(){ System.out.println("這里是修改訂單功能"); searchAll(); System.out.println("請輸入要修改編號"); int index=-1; int num1=input1.nextInt(); for(int i=0;i<flower.length;i++){ Flower f=flower[i]; int number=f.getNumber(); if(num1==number) index=i; } if(index==-1)System.out.println("輸入的編號有誤"); else{System.out.println("請輸入改變后的鮮花名稱"); String name=input1.next(); System.out.println("請輸入改變后的銷售數(shù)量"); int number=input1.nextInt(); System.out.println("請輸入改變后的價(jià)格"); double price =input1.nextDouble(); System.out.println("請輸入改變后的銷售日期"); String date =input1.next(); System.out.println("請輸入改變后的銷售員"); String saler=input1.next(); System.out.println("你確定要修改嗎?(y/n)"); String choice=input1.next(); if("y".equals(choice)){ flower[index].setName(name); flower[index].setCount(number);; flower[index].setPrice(price); flower[index].setDate(date); flower[index].setSaler(saler); } System.out.println("修改后的全部訂單"); searchAll(); } } //刪除訂單功能 public void deleteSale(){ System.out.println("這里是刪除訂單功能"); searchAll(); System.out.println("請輸入要?jiǎng)h除的編號"); int number=input1.nextInt(); int index=-1; for(int i=0;i<flower.length;i++){ Flower f=flower[i]; if(number==f.getNumber()) index=i; } if(index==-1)System.out.println("你輸入的編號有誤"); else{System.out.println("你要修改的訂單如下"); Flower f=flower[index]; System.out.println("編號\t鮮花名稱\t銷售數(shù)量\t價(jià)格\t銷售日期\t\t銷售員"); System.out.println(f.getNumber()+"\t"+f.getName()+"\t"+f.getCount()+"\t" +f.getPrice()+"\t" +f.getDate()+"\t"+f.getSaler()); System.out.println("你確定要?jiǎng)h除嗎(y/n)"); System.out.println("請選擇"); String choice=input1.next(); if("y".equals(choice)){ **for(int i=index;i<flower.length-1;i++){ flower[i]=flower[i+1];** } **flower[flower.length-1]=null;** System.out.println("刪除成功"); searchAll(); } else {System.out.println("已取消刪除");} } } }
import java.util.Scanner; public class test { public static void main(String[] args) { do{Scanner input=new Scanner(System.in);//打印對象 FlowerMgr f=new FlowerMgr(); f.mainMenu(); System.out.println("請選擇"); int num=input.nextInt(); //方法的選用 switch(num){ case 1: f.searchAll();break;//查詢銷售訂單 case 2:f.updateSale();break;//修改訂單功能 case 3:f.deleteSale();break;//刪除功能 case 4: return; }}while(true); } }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Java實(shí)戰(zhàn)花店商城系統(tǒng)的實(shí)現(xiàn)流程
- Java實(shí)現(xiàn)茶葉售賣商城系統(tǒng)(java+SSM+JSP+EasyUi+mysql)
- Java 仿天貓服裝商城系統(tǒng)的實(shí)現(xiàn)流程
- Java女裝商城系統(tǒng)的實(shí)現(xiàn)流程
- Java 文創(chuàng)商城系統(tǒng)的實(shí)現(xiàn)流程
- Java 實(shí)戰(zhàn)項(xiàng)目錘煉之在線蛋糕商城系統(tǒng)的實(shí)現(xiàn)
- Java 實(shí)戰(zhàn)項(xiàng)目錘煉之在線購書商城系統(tǒng)的實(shí)現(xiàn)流程
- Java 實(shí)戰(zhàn)項(xiàng)目錘煉之網(wǎng)上商城系統(tǒng)的實(shí)現(xiàn)流程
- Java畢業(yè)設(shè)計(jì)實(shí)戰(zhàn)項(xiàng)目之在線服裝銷售商城系統(tǒng)的實(shí)現(xiàn)流程
相關(guān)文章
基于java swing實(shí)現(xiàn)答題系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了基于java swing實(shí)現(xiàn)答題系統(tǒng),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01Java旋轉(zhuǎn)數(shù)組中最小數(shù)字具體實(shí)現(xiàn)(圖文詳解版)
這篇文章主要給大家介紹了關(guān)于Java旋轉(zhuǎn)數(shù)組中最小數(shù)字具體實(shí)現(xiàn)的相關(guān)資料,旋轉(zhuǎn)數(shù)組,說明數(shù)據(jù)不變,只是改變位置,文中通過代碼示例介紹的非常詳細(xì),需要的朋友可以參考下2023-08-08Java struts2 validate用戶登錄校驗(yàn)功能實(shí)現(xiàn)
這篇文章主要為大家詳細(xì)介紹了Java struts2 validate用戶登錄校驗(yàn)功能實(shí)現(xiàn)的具體步驟,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-05-05springboot 使用ThreadLocal的實(shí)例代碼
這篇文章主要介紹了springboot 使用ThreadLocal的實(shí)例代碼,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-12-12java數(shù)據(jù)結(jié)構(gòu)實(shí)現(xiàn)雙向鏈表功能
這篇文章主要為大家詳細(xì)介紹了java數(shù)據(jù)結(jié)構(gòu)實(shí)現(xiàn)雙向鏈表功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11java中ImageReader和BufferedImage獲取圖片尺寸實(shí)例
這篇文章主要介紹了java中ImageReader和BufferedImage獲取圖片尺寸實(shí)例,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-01-01Mybatis傳參為逗號分隔的字符串情形進(jìn)行in條件查詢方式
這篇文章主要介紹了Mybatis傳參為逗號分隔的字符串情形進(jìn)行in條件查詢方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-01-01使用Java實(shí)現(xiàn)查找并移除字符串中的Emoji
Emoji 實(shí)際上是 UTF-8 (Unicode) 字符集上的特殊字符,這篇文章主要介紹了如何使用Java實(shí)現(xiàn)查找并移除字符串中的Emoji,感興趣的可以了解下2024-03-03