当前位置: 首页 > news >正文

ArrayList综合案例-模拟外卖中的商家系统

一案例要求:

二代码要求:

package 重修;import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;import static java.lang.System.exit;public class first {public static  void main(String[] args) {Scanner sc=new Scanner(System.in);int flag=0;ArrayList<javabean> a=new ArrayList<>();while (true) {System.out.println("1商品上架  2商品查询 3退出");System.out.println("请输入选择");int y= sc.nextInt();switch (y) {case 1:if (flag==0) {System.out.print("请决定上架数量:");int x = sc.nextInt();javabean[] beans = new javabean[x];for (int i = 0; i < x; i++) {System.out.println("第" + (i + 1) + "个商品上架");String name= null;System.out.println("商品名字:");while (true) {name = sc.next();for (int j = 0; j < beans.length; j++) {}}System.out.println("商品价格");double price=sc.nextDouble();System.out.println("商品描述:");String sexcribe=sc.next();beans[i]=new javabean(name,price,sexcribe);a.add(beans[i]);}flag=1;break;} else{System.out.println("商品上架已完成");break;}case 2:if (flag==0){System.out.println("请先完成商品上架");break;}else{while (true) {System.out.println("1展示全部商品信息  2查询某一商品信息(名字) 3返回上一级");System.out.println("请选择");int n=sc.nextInt();switch (n){case 1:System.out.println("a.size为"+a.size());for (int i = 0; i < a.size(); i++) {System.out.println("名字"+a.get(i).getName()+"价格"+a.get(i).getPrice()+"描述"+a.get(i).getDescribe());}break;case 2:System.out.println("请输入商品名字:");String k=sc.next();for (int i = 0; i < a.size(); i++) {if(a.get(i).getName().equals(k)){System.out.println("名字"+a.get(i).getName()+"价格"+a.get(i).getPrice()+"描述"+a.get(i).getDescribe());break;}System.out.println("暂无该信息,请重新输入商品名字");}case 3:break;default:System.out.println("选择错误,请重新选择!");}}}case 3:exit(0);default:System.out.println("选择错误,请重新选择!");}}

三运行结果:

http://www.lryc.cn/news/393942.html

相关文章:

  • Postgres JSON字段怎么修改key的名称
  • GStreamer学习5----probe数据探测
  • Open3D 点云的圆柱形邻域搜索
  • python如何设计窗口
  • C语言获取当前时间
  • 【每日一练】python三目运算符的用法
  • CentOS 7.9 停止维护(2024-6-30)后可用在线yum源 —— 筑梦之路
  • Git 常用命令备忘
  • Ubuntu24.04安装Skynet环境
  • 【C++】cout.self()函数
  • VueQuill 富文本编辑器技术文档快速上手
  • 链式二叉树oj题
  • Curator 是一个开源工具为 Elasticsearch 集群设计,用于自动化索引的维护任务。
  • STM32-PWR和WDG看门狗
  • C++循环队列 经典示例
  • 【程序大侠传】大表分库分表切换数据库类型导致pagehelper生成sql语法报错
  • 7、Redis 队列与 Stream
  • FFT剖析
  • git clone报错RPC failed; curl 92 HTTP/2 stream 7 was not closed cleanly
  • Apispec,一个用于生成 OpenAPI(Swagger)规范的 Python 库
  • SpringBoot 自定义异常返回数据格式
  • 【xinference】(15):在compshare上,使用docker-compose运行xinference和chatgpt-web项目,配置成功!!!
  • 【Unity 3D角色移动】
  • 个人视角,社会影响力:自媒体的魅力所在
  • 算法训练营day70
  • EtherCAT转Profinet网关配置说明第二讲:上位机软件配置
  • 日志自动分析-Web---360星图GoaccessALBAnolog
  • 【面试八股文】java基础知识
  • ssrf结合redis未授权getshell
  • 魔法自如:精通 IPython %automagic 命令的切换艺术