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;

Similar Posts

发表评论

邮箱地址不会被公开。 必填项已用*标注