超市管理系统(JAVA)源代码

Good商品货物类

package ShoppingSystem;

//商品类:商品编号、商品单价、商品名称
public class Good {
    private int id;
    private double pirce;
    private String name;
    
//无参构造方法
    public Good() {
    }
    
//有参构造方法
    public Good(int id, double pirce, String name) {
        this.id = id;
        this.pirce = pirce;
        this.name = name;
    }
    
//将toString方法重写
    @Override
    public String toString() {
        return   id +"\t" +pirce + "\t"+name ;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public double getPirce() {
        return pirce;
    }

    public void setPirce(double pirce) {
        this.pirce = pirce;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

ShoppingSystem超市管理系统测试类

package ShoppingSystem;
import java.util.Arrays;
import java.util.Scanner;

public class ShoppingSystem {
    public static void main(String[] args) {

        //1.定义对象数组并赋值
        Good[] goods = new Good[3];
        goods[0] =new Good(1000,10.0,"笔记本") ;
        goods[1] =new Good(1001,2.0,"西红柿") ;
        goods[2] =new Good(1002,5.0,"辣条") ;

        //2.创建Scanner对象并调用获取控制台输入信息的方法
        Scanner sc = new Scanner(System.in);

        //3.定义循环条件
        boolean isWork=true;
        //4.定义操作商品编号
        int indexNum;
        //5.定义操作的商品编号的下标
        int index=0;

        while (isWork){
            System.out.println("===================超市管理系统==================");
            System.out.println("1:货物清单\t2:增加货物\t3:删除货物\t4:修改货物\t5:退出");
            System.out.println("输出你要操作的编号:");
            int choseNum = sc.nextInt();
            System.out.println();

               //1:货物清单
            if(choseNum==1){
                System.out.println("===================商品清单==================");
                System.out.println("商品编号\t商品单价\t商品名称");
                for (int i = 0; i 

注意:只有在先添加商品成功的情况下,才可以进行下面的操作!

你可能感兴趣的:(java,开发语言)