水果管理系统Java版分享给大家。
主类FruitsDemo
/* * *功能: * 1。查看所有的水果 * 2。添加新的水果(添加的时候判断水果名是否有重复) * 3。对所有的水果进行排序(价格排序,库存排序) * 4。删除指定的水果 * 5。退出系统 * *注意: * 1。每种水果都必须有水果id、水果名,水果数量,水果价格 * 2。添加水果时,要由用户输入水果名,数量和价格 * 3。删除水果时要二次确认 * *评分依据:功能实现的情况,代码规范性(命名规范,格式规范),设计的合理性 * @author yj * */公开课FruitsDemo { 公共静态void main (String [] args) { int选择=0;//主菜单功能选择 布尔isStart=true;//程序运行标志位 而(isStart) { system . out。println(“* * * * * * * * * * * * * * * * * *水果管理系统* * * * * * * * * * * * * * * * * * \ n请输入下列序号选择相应功能:\ n \ n 1。查看所有的水果\ t2。添加新的水果\ n 3。对所有的水果进行排序查看(价格排序,库存排序)\ n 4。删除水果\ t5。退出系统”); 选择=Calculation.inputIsInt (); 开关(select) { 案例1://1。查看所有的水果 Calculation.seeAllFruits (); 打破; 案例2://2。添加新的水果 Calculation.add (); 打破; 案例3://3。对所有的水果进行排序查看(价格排序,库存排序) Calculation.Sort (); 打破; 案例4://4。删除水果 System.out.println(“请输入你要删除的水果”); 字符串指数=Calculation.inputIsString (); System.out.println(“二次确认! ! !请再次输入你要删除的水果”); 字符串index1=Calculation.inputIsString (); 如果(index.equals (index1)) { Calculation.remove(指数); 其他}{ System.out.println(“两次输入不匹配,删除失败! ! !”); } 打破; 案例5://5。退出系统 isStart=false; 打破; 默认值: System.out.println(“输入错误,请重新输入”); 打破; } } System.out.println(“程序已退出,欢迎使用! ! !”); } } >之前水果类
/* * *水果类 * @author yj * */公共类水果{//每种水果都必须有水果id、水果名,水果数量,水果价格 私人int id;//id 私人int num;//数量(库存) 私人字符串名称;//水果名 私人双价格;//水果价格 公共水果(int id字符串名称、int num双价格){ 超级(); 这一点。id=id; 这一点。num=num; this.name=名称; 这一点。价格=价格; } 公共int getId () { 返回id; } 公共空间setId (int id) { 这一点。id=id; } 公共int getNums () { 返回num; } 公共空间setNums (int num) { 这一点。num=num; } 公共字符串getName () { 返回名称; } 公共空间setName(字符串名称){ this.name=名称; } 公共双getPrice () { 回报价格; } 公共空间setPrice(双价格){ 这一点。价格=价格; } } >之前计算类
进口java.util.Collections; 进口java.util.Comparator; 进口java.util.Iterator; 进口java.util.LinkedList; 进口java.util.Scanner;/* * *计算类,存放关于计算处理数据的函数 * * @author yj * */公共类计算{ 静态LinkedList列表=new LinkedList (); 静态扫描sc=new扫描仪(系统); 静态int id=1;/* * *添加水果get () */公共静态孔隙add () { int num; 字符串名称; 两倍价格; System.out.print(“请输入你要添加的水果名,数量(单位:个)和价格(单位:元)\ n”); name=Calculation.inputIsString (); num=Calculation.inputIsInt (); 价格=Calculation.inputIsDouble (); 如果(cals(名称、num价格)){ 列表。(新添加水果(id、名称、num、价格); id + +; } }/* * *查看所有水果seeAllFruits () */公共静态孔隙seeAllFruits () { 如果(list.size ()==0) { System.out.println(“数据为空! ! !”); 其他}{ Iterator Java版水果管理系统源码