java實(shí)現(xiàn)超市管理系統(tǒng)
本文實(shí)例為大家分享了java實(shí)現(xiàn)超市管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
實(shí)現(xiàn)功能
使用選擇結(jié)構(gòu),循環(huán)結(jié)構(gòu),數(shù)組的知識(shí)實(shí)現(xiàn)一個(gè)超市管理系統(tǒng)
運(yùn)行結(jié)果:貨物清單:
添加商品功能:
刪除商品功能:
修改商品:
商品貨物實(shí)體類(lèi)
import java.util.Arrays; public class Goods { private int id; private double price; private String name; public Goods(int id, double price, String name) { this.id = id; this.price = price; this.name = name; } public int getId() { return id; } public void setId(int id) { this.id = id; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Goods() { } //增加商品 public Goods[] add(Goods[]goods,Goods newGood){ goods= Arrays.copyOf(goods,goods.length+1); goods[goods.length-1]=newGood; return goods; } //刪除商品 public static Goods[] del(Goods[]goods,int id){ int i=0; while(true){ if(goods[i].getId()==id){ goods[i]=null; return goods; } i++; if(i>=goods.length){ return goods; } } } //添加商品 public static Goods[] change(Goods[]goods,int id,int newId,double newPrice,String newName){ int i=0; while (true){ if(goods[i].getId()==id){ goods[i].setId(newId); goods[i].setPrice(newPrice); goods[i].setName(newName); return goods; } i++; if(i>=goods.length){ return goods; } } } }
超市管理系統(tǒng)類(lèi)
import java.util.Scanner; public class marketManager { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Goods g1=new Goods(1000,10,"筆記本"); Goods g2=new Goods(1001,2,"西紅柿"); Goods g3=new Goods(1002,5,"辣條"); Goods []goods={g1,g2,g3}; while (true) { System.out.println("========超市管理系統(tǒng)======="); System.out.println("1.貨物清單 2.增加商品 3.刪除商品 4.修改商品 5.退出"); System.out.println("請(qǐng)輸入你要操作的編號(hào):"); int i = sc.nextInt(); switch (i){ case 1: System.out.println("=======商品清單======="); System.out.println("商品編號(hào)"+"\t\t"+"商品單價(jià)"+"\t\t"+"商品名稱(chēng)"); for (Goods a:goods) { if(a==null){ continue; } System.out.println(a.getId()+"\t\t"+a.getPrice()+"\t\t"+a.getName()); } continue; case 2: System.out.println("你選擇的是增加商品的功能"); System.out.println("請(qǐng)輸入你要添加的編號(hào):"); int Id = sc.nextInt(); System.out.println("請(qǐng)輸入你要添加的商品價(jià)格:"); double price = sc.nextDouble(); System.out.println("請(qǐng)輸入你要添加的商品名稱(chēng)"); String name = sc.next(); Goods good=new Goods(Id,price,name); goods = good.add(goods, good); System.out.println("添加成功!"); continue; case 3: System.err.println("你選擇的是刪除商品功能"); System.out.println("請(qǐng)輸入你要操作的編號(hào):"); Id = sc.nextInt(); goods=Goods.del(goods,Id); System.out.println("刪除成功!"); continue; case 4: System.out.println("你選擇的是修改商品功能"); System.out.println("請(qǐng)輸入你要操作的編號(hào):"); Id=sc.nextInt(); System.out.println("請(qǐng)輸入修改后的編號(hào):"); int newId = sc.nextInt(); System.out.println("請(qǐng)輸入修改后的價(jià)格:"); double newPrice = sc.nextDouble(); System.out.println("請(qǐng)輸入修改后的商品名稱(chēng):"); String newName=sc.next(); goods=Goods.change(goods,Id,newId,newPrice,newName); continue; case 5: return; } } } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Java 實(shí)戰(zhàn)練手項(xiàng)目之校園超市管理系統(tǒng)的實(shí)現(xiàn)流程
- 基于Mysql+JavaSwing的超市商品管理系統(tǒng)設(shè)計(jì)與實(shí)現(xiàn)
- java實(shí)現(xiàn)簡(jiǎn)易超市管理系統(tǒng) 附源碼下載
- java實(shí)現(xiàn)簡(jiǎn)單的小超市程序
- java實(shí)現(xiàn)簡(jiǎn)單超市管理系統(tǒng)
- java實(shí)現(xiàn)超市庫(kù)存管理系統(tǒng)
- java實(shí)現(xiàn)超市商品庫(kù)存管理平臺(tái)
- java實(shí)現(xiàn)水果超市管理系統(tǒng)
- Java編寫(xiě)網(wǎng)上超市購(gòu)物結(jié)算功能程序
- Java實(shí)現(xiàn)超市會(huì)員管理系統(tǒng)
相關(guān)文章
SpringBoot利用jackson格式化時(shí)間的三種方法
日常開(kāi)發(fā)過(guò)程中經(jīng)常會(huì)使用json進(jìn)行數(shù)據(jù)的傳輸,這就涉及到了對(duì)象和json的相互轉(zhuǎn)化,常用的解決方案有:Jackson(推薦)、谷歌的Gson、阿里的Fastjson,這篇文章主要給大家介紹了關(guān)于SpringBoot如何利用jackson格式化時(shí)間的相關(guān)資料,需要的朋友可以參考下2021-06-06Java File類(lèi)的簡(jiǎn)單使用教程(創(chuàng)建、刪除、遍歷與判斷是否存在等)
這篇文章主要給大家介紹了關(guān)于Java File類(lèi)的簡(jiǎn)單使用(創(chuàng)建、刪除、遍歷與判斷是否存在等)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12springboot讀取自定義配置文件時(shí)出現(xiàn)亂碼解決方案
這篇文章主要介紹了springboot讀取自定義配置文件時(shí)出現(xiàn)亂碼解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-11-11spring boot 使用@Async實(shí)現(xiàn)異步調(diào)用方法
本篇文章主要介紹了spring boot 使用@Async實(shí)現(xiàn)異步調(diào)用方法,具有一定的參考價(jià)值,有興趣的可以了解一下。2017-04-04Java集合類(lèi)之Map集合的特點(diǎn)及使用詳解
這篇文章主要為大家詳細(xì)介紹一下Java集合類(lèi)中Map的特點(diǎn)及使用,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)Java有一定幫助,感興趣的可以了解一下2022-08-08mybatis的映射xml中動(dòng)態(tài)設(shè)置orderby方式
這篇文章主要介紹了mybatis的映射xml中動(dòng)態(tài)設(shè)置orderby方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-11-11理解java和python類(lèi)變量以及類(lèi)的成員變量
這篇文章主要幫助大家理解java和python類(lèi)變量以及類(lèi)的成員變量,用實(shí)例進(jìn)行解析,感興趣的朋友可以參考一下2016-02-02