java if菜鸟_面向对象(java菜鸟的课堂笔记)

import java.util.*;                          //调包

public class Main{                          //建一个主类

static Scanner sc = newScanner(System.in);static int i = 0;static Chaoshi[] shop = new Chaoshi[100];public static void main(String[] args){              //主入口

menu();                           //调用菜单方法

}public static void menu(){                    //定义一个菜单方法

System.out.println("============================");

System.out.println("》欢迎进入超市库存统计系统《");

System.out.println("=》 请输入对应数字进行操作《");

System.out.println("=======》 1,进货存储 《");

System.out.println("=======》 2,修改信息 《");

System.out.println("=======》 3,查询库存 《");

System.out.println("=======》 4,退出操作系统 《");

System.out.println("============================");int a = sc.nextInt();                      //用户输入

switch(a){case 1:adds(); break;case 2:update(); break;case 3:select(); break;case 4:exit(); break;default:System.out.println("====输入有误,请重新输入====");

menu();break;

}

}public static void adds(){                      //定义一个存货方法

System.out.println("=========请输入货物名称=========");

String sname=sc.next();

System.out.println("=========请输入货物类型=========");

String sclass=sc.next();

System.out.println("=========请输入货物价格=========");

String sprice=sc.next();

System.out.println("=========请输入货物数量=========");

String snum=sc.next();

Chaoshi shop1= newChaoshi(sname,sclass,sprice,snum);

shop[i]=shop1;

i++;

System.out.println("输入成功,继续输入(1),返回菜单(2)");int flage =sc.nextInt();if(flage==1){

adds();

}elsemenu();

}public static void update(){                      //定义一个修改方法

System.out.println("请输入商品名称,为您修改");

String b=sc.next();for(i=0;i<100;i++){if(b.equals(shop[i].sname)){

System.out.println("===================查询结果如下===================");

shop[i].say();

System.out.println("=========请输入修改后货物名称=========");

String sname=sc.next();

System.out.println("=========请输入修改后货物类型=========");

String sclass=sc.next();

System.out.println("=========请输入修改后货物价格=========");

String sprice=sc.next();

System.out.println("=========请输入修改后货物数量=========");

String snum=sc.next();

Chaoshi shop1= newChaoshi(sname,sclass,sprice,snum);

shop[i]=shop1;

System.out.println("继续修改(1),返回菜单(2)");int flage =sc.nextInt();if(flage==1){

update();

}elsemenu();

}

}

}public static void select(){                      //定义一个查询方法

System.out.println("指定查询(1),全部查询(2)");int a =sc.nextInt();if(a==1){

System.out.println("请输入商品名称,为您查询");

String b=sc.next();for(i=0;i<100;i++){if(b.equals(shop[i].sname)){

System.out.println("===================查询结果如下===================");

shop[i].say();

System.out.println("继续查询(1),返回菜单(2)");int flage =sc.nextInt();if(flage==1){

select();

}elsemenu();

}

}

}else{for(Chaoshi s:shop){if(s!=null){

s.say();

}

}

System.out.println("继续查询(1),返回菜单(2)");int flage =sc.nextInt();if(flage==1){

select();

}elsemenu();

}

}public static void exit(){                      //定义一个退出方法

System.out.println("===》》》您已退出操作系统《《《===");

System.exit(0);

}

}public class Chaoshi{                          //新建一个超市类

String sname;

String sclass;

String sprice;

String snum;publicChaoshi(String sname,String sclass,String sprice,String snum){this.sname =sname;this.sclass =sclass;this.sprice =sprice;this.snum =snum;

}public voidsay(){

System.out.println("名称:"+sname+"\n种类:"+sclass+"\n价格:"+sprice+"\n数量:"+snum+"\n");  //定义一个输出方式

}

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值