简单基础的超市管理系统源代码

package cc.openhome;


import java.awt.FlowLayout;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
/**
 * Spgl  食品管理
 * shipin 食品
 * biaohao 标号
 * mignxheng 名称
 * jiage 价格
 * bh标号   jg价格      mc名称
 * @author Administrator
 *
 */
public class Demo2 {
public static void main(String[] args)throws Exception {//抛出异常
Spgl shipin=new Spgl();//创建食品管理的对象
BufferedReader sr=new BufferedReader(new InputStreamReader(System.in));//创建了一个BufferedReader对象, 名字是bufferedReader , 
//然后new, 传入了一个InputStream对象.
//这个类就是一个包装类,它可以包装字符流,将字符流放入缓存里,先把字符读到缓存里,
//到缓存满了或者你flush的时候,再读入内存,就是为了提供读的效率而设计的。
//BufferedReader是缓冲流, InputStream是字节流。
while(true){//while循环
System.out.println("请按提示选择一下功能");
System.out.println("添加食品请按1");
System.out.println("查找食品信息请按2");
System.out.println("修改食品价格请按3");
System.out.println("删除食品请按4");
System.out.println("退出请按0");

String string=sr.readLine();//读入用户输入的字符串
if (string.equals("1")) {
System.out.println("请输入食品编号");
String bh=sr.readLine();
System.out.println("请输入食品名称");
String mc=sr.readLine();
System.out.println("请输入食品价格");
float jg=Float.parseFloat(sr.readLine());

Sp sp=new Sp(bh, mc, jg);//创建食品对象 
shipin.addsp(sp);//
}
else if (string.equals("2")) {
System.err.println("请输入食品编号");
String bh=sr.readLine();
shipin.spxx(bh);
}
else if (string.equals("3")) {
System.out.println("请输入食品编号");
String bh=sr.readLine();
System.out.println("请输入食品价格");
float jg=Float.parseFloat(sr.readLine());
shipin.spjg(bh,jg);
}
else if (string.equals("4")) {
System.out.println("请输入食品编号");
String bh=sr.readLine();
shipin.delsp(bh);
}
else  if (string.equals("0")) {
System.out.println("感谢你的使用,再见");
System.exit(0);
}
else {
System.out.println("输入有误");
}
}
}
}
/**
 * 食品管理集合类
 * @author Administrator
 *
 */
class Spgl{
private ArrayList aa=null;
public Spgl() {
// TODO Auto-generated constructor stub
aa=new ArrayList();//构造ArrayList方法,食品管理类 包过 添加 查询 修改 删除等操作
}
/**
* 添加食品的方法
* @param sp
*/
public  void addsp(Sp sp){
aa.add(sp);
System.out.println("添加食品成功!");
}
/**
* 查找显示食品的信息
* @param bh
*/
public void spxx(String bh){
int i;
for ( i = 0; i < aa.size(); i++) {
Sp sp=(Sp)aa.get(i);
if (sp.getBianhao().equals(bh)) {
System.out.println("该食品的信息为:");
System.out.println("食品编号:"+bh);
System.out.println("食品名称:"+sp.getMingcheng());
System.out.println("食品价格:"+sp.getJiage()+"元");
break;
}
}
if (i==aa.size()) {
System.out.println("对不起,无此食品!");
}
}
/**
* 修改食品价格
* @param bh
* @param jg
*/
public void spjg(String bh,float jg){
int i;
for ( i = 0; i < aa.size(); i++) {
Sp sp=(Sp)aa.get(i);
if (sp.getBianhao().equals(bh)) {
sp.setJiage(jg);
System.out.println("修改食品价格成功!");
break;
}
}
if (i==aa.size()) {
System.out.println("对不起,没有找到相应的食品,修改成功");

}
}
/**
* 删除食品
* @param bh
*/
public void delsp(String bh){
int i;
if (aa.size()==0) {
System.out.println("对不起,仓库中已没有任何食品!");
}
for (i = 0;  i<aa.size(); i++) {
Sp sp=(Sp)aa.get(i);
if (sp.getBianhao().equals(bh)) {
aa.remove(i);
System.out.println("删除食品成功!");
break;
}
}
if ((i==aa.size())&&(aa.size()!=0)) {
System.out.println("对不起,没有该食品!");
}
}
}
/**
 * 食品类的基本信息
 * @author Administrator
 *
 */
class Sp{
private String bianhao;
private String mingcheng;
private float jiage;
public Sp(String bianhao,String mingcheng,Float jiage) {
// TODO Auto-generated constructor stub
this.bianhao=bianhao;
this.mingcheng=mingcheng;
this.jiage=jiage;
}
/**
* get set构造方法
* @return
*/
public String getBianhao() {
return bianhao;
}
public void setBianhao(String bianhao) {
this.bianhao = bianhao;
}
public String getMingcheng() {
return mingcheng;
}
public void setMingcheng(String mingcheng) {
this.mingcheng = mingcheng;
}
public float getJiage() {
return jiage;
}
public void setJiage(float jiage) {
this.jiage = jiage;
}
}

  • 7
    点赞
  • 62
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 20
    评论
评论 20
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阳光不锈@

如果有帮助的话,打赏一下吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值