久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

java實現超市管理系統

瀏覽:4日期:2022-08-19 11:13:59

本文實例為大家分享了java實現超市管理系統的具體代碼,供大家參考,具體內容如下

實現功能

使用選擇結構,循環結構,數組的知識實現一個超市管理系統

運行結果:貨物清單:

java實現超市管理系統

添加商品功能:

java實現超市管理系統

刪除商品功能:

java實現超市管理系統

修改商品:

java實現超市管理系統

商品貨物實體類

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; } } }}

超市管理系統類

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('========超市管理系統======='); System.out.println('1.貨物清單 2.增加商品 3.刪除商品 4.修改商品 5.退出'); System.out.println('請輸入你要操作的編號:'); int i = sc.nextInt(); switch (i){ case 1: System.out.println('=======商品清單======='); System.out.println('商品編號'+'tt'+'商品單價'+'tt'+'商品名稱'); for (Goods a:goods) { if(a==null){ continue; } System.out.println(a.getId()+'tt'+a.getPrice()+'tt'+a.getName()); } continue; case 2: System.out.println('你選擇的是增加商品的功能'); System.out.println('請輸入你要添加的編號:'); int Id = sc.nextInt(); System.out.println('請輸入你要添加的商品價格:'); double price = sc.nextDouble(); System.out.println('請輸入你要添加的商品名稱'); 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('請輸入你要操作的編號:'); Id = sc.nextInt(); goods=Goods.del(goods,Id); System.out.println('刪除成功!'); continue; case 4: System.out.println('你選擇的是修改商品功能'); System.out.println('請輸入你要操作的編號:'); Id=sc.nextInt(); System.out.println('請輸入修改后的編號:'); int newId = sc.nextInt(); System.out.println('請輸入修改后的價格:'); double newPrice = sc.nextDouble(); System.out.println('請輸入修改后的商品名稱:'); String newName=sc.next(); goods=Goods.change(goods,Id,newId,newPrice,newName); continue; case 5: return; } } }}

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

標簽: Java
相關文章:
主站蜘蛛池模板: 呼图壁县| 镇坪县| 鹿泉市| 合阳县| 南通市| 甘谷县| 图片| 陆丰市| 南丹县| 梁山县| 海城市| 石泉县| 丹阳市| 吴旗县| 宝山区| 侯马市| 施甸县| 阿克苏市| 隆德县| 文水县| 临泉县| 顺昌县| 浦北县| 花垣县| 若尔盖县| 赤水市| 华坪县| 东莞市| 綦江县| 娄底市| 丹阳市| 威宁| 平远县| 蓬莱市| 兰西县| 沿河| 宝丰县| 孙吴县| 峨眉山市| 和龙市| 岗巴县|