java商品_java 商品 系统 代码

这是一个简单的Java商品管理系统,包括两个类:Goods用于实例化商品对象,包含名称、价格、数量、编号、类型和供应商等属性;shopManagement类包含主方法,用于录入和查询商品信息。在录入循环中,用户输入商品各项信息并存储为Goods对象。查询循环中,用户输入商品名称以查询对应的商品详情。程序目前存在错误,无法正常运行。
摘要由CSDN通过智能技术生成

里面分为两个类,一个是Goods;类,用来实例化对象的;shopmanagement是存放主方法的类。Goods;类包括成员变量(名称,价格,数量,编号,类型,供应商),每个成员变量都是private类型...

里面分为两个类,一个是Goods;类,用来实例化对象的;shopmanagement是存放主方法的类。Goods;类包括成员变量 (名称,价格,数量,编号,类型,供应商),每个成员变量都是private类型,都有相对应的get和set方法(好像用不到我就不写了);我加了个prt(也就是print)的方法,当主方法调用查询功能的时候可以使用实例化对象的prt方法输出商品信息。

shopmanagement类的主方法包括两个循环,一个循环用来录入商品信息,另一个循环来查询商品信息,总报错无法运行,大神帮我看看怎么处理,是在解决不掉

package shopmanagement;

import java.util.Scanner;

class Goods {

private String name;

private int price;

private int sum;

private int code;

private String type;

private String supplier;

Goods(String name, int price, int sum, int code, String type, String supplier) {

this.name = name;

this.price = price;

this.sum = sum;

this.code = code;

this.type = type;

this.supplier = supplier;

}

public void prt() {

System.out.print("商品名称:" + this.name + "\t");

System.out.print("价格" + this.name + "\t");

System.out.print("库存:" + this.name + "\t");

System.out.print("编号:" + this.name + "\t");

System.out.print("类型:" + this.name + "\t");

System.out.print("供应商:" + this.name + "\t");

}

}

public class shopManagement {

public static void main(String[] args) {

System.out.println("********************商品管理系统********************");

System.out.println("********是否执行录入功能?Y执行,N切换到查询功能;********");

Scanner sc = new Scanner(System.in);

/*

* 循环录入功能

*/

String function = sc.nextLine();

int i = 0;

Goods[] goods = null;

for (;;) {

if (function.equals("N")) {

System.out.println("切换到查询功能");

break;

}

System.out.println("商品名称(enter键结束):");

String name = sc.nextLine();

System.out.println("价格(enter键结束):");

int price = sc.nextInt();

System.out.println("存量(enter键结束):");

int sum = sc.nextInt();

System.out.println("编号(enter键结束):");

int code = sc.nextInt();

System.out.println("类型(enter键结束):");

String type = sc.nextLine();

System.out.println("供应商(enter键结束):");

String supplier = sc.nextLine();

goods[i] = new Goods(name, price, sum, code, type, supplier);

i++;

sc.close();

}

/*

* 循环查询功能

*/

int j = 0;

System.out.println("是否继续操作?Y继续或N退出");

String function2 = new Scanner(System.in).nextLine();

for (;;) {

if (function2.equals("N")) {

System.out.println("正在退出");

System.exit(0);

System.out.println("输入品名");

String find = new Scanner(System.in).nextLine();

for (int k = 0; k < goods.length; k++) {

if (find.equals(goods[k].getName())) {

goods[k].prt();

}

}

}

}

}

}

展开

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值