标题: 好有成就啊,今天休息一天,但是学会了好多感觉!!! [打印本页] 作者: 驰骋向前 时间: 2016-12-3 00:35 标题: 好有成就啊,今天休息一天,但是学会了好多感觉!!! /*1.主页 创建类 调用类
* Scanner sc = new Scanner(System.in);
* int user= sc.nextInt();
* System.out.println("");
* 集合
* 2.添加货物清单 System.out.println("");
* 3.删除货物 Scanner sc = new Scanner(System.in);
* int user= sc.nextInt();
* arr.remove();
* 4.修改货物Scanner sc = new Scanner(System.in);
* int user= sc.nextInt();
* 5.退出 return exit
*
*/
import java.util.ArrayList;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
ArrayList<fruit> a = new ArrayList<fruit>();
System.out.println("--------欢迎光临""驰骋向前""超市--------");
System.out.println("1.货物清单");
System.out.println("2.添加新货物");
System.out.println("3.删除货物");
System.out.println("4.修改货物");
System.out.println("5.退出系统");
System.out.println("----------------------------");
cc(a);
int s = 0;
while (s<2){
System.out.println("请输入要操作的功能序号:");
Scanner sc = new Scanner(System.in);
int user= sc.nextInt();
switch (user){
case 1:
qd(a);
break;
case 2:
tj(a);
break;
case 3:
sc (a);
break;
case 4:
xg(a);
break;
case 5:
tc();
return;
default:
System.out.println("别闹了,就5个序号");
break;
}
}
}
//存储库存
public static void cc(ArrayList<fruit> a) {
fruit f1 = new fruit();
f1.sg="苹果";
f1.jg=2.5;
f1.kc=10;
fruit f2 = new fruit();
f2.sg="香蕉";
f2.jg=3;
f2.kc=10;
fruit f3 = new fruit();
f3.sg="火龙果";
f3.jg=6;
f3.kc=10;
a.add(f1);
a.add(f2);
a.add(f3);
}
//打印清单
public static void qd(ArrayList<fruit> a) {
System.out.println("-------------商品库存清单-----------");
System.out.println("名称 价格 库存");
for(int i=0;i<a.size();i++){
fruit f = a.get(i);
System.out.println(f.sg+" "+f.jg+" "+f.kc);
}
}
//增加货物
public static void tj(ArrayList<fruit> a) {
Scanner sc = new Scanner(System.in);
fruit f = new fruit();
System.out.println("请输入新货物的名称");
f.sg= sc.next();
System.out.println("请输入新货物的价格");
f.jg= sc.nextDouble();
System.out.println("请输入新货物的库存");
f.kc= sc.nextInt();
a.add(f);
}
//删除货物
public static void sc(ArrayList<fruit> a) {
System.out.println("请输入要删除的货物价格:");
Scanner sc = new Scanner(System.in);
double price = sc.nextDouble();
for (int i=0;i<a.size();i++){
fruit f = a.get(i);
if (f.jg == price){
a.remove(f);
System.out.println("删除完毕");
return;
}
}
}
//修改货物
public static void xg(ArrayList<fruit> a) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入要修改的货物价格:");
double price = sc.nextDouble();
for (int i=0;i<a.size();i++){
fruit f = a.get(i);
if (f.jg == price){
System.out.println("请输入新货物的名称");
f.sg= sc.next();
System.out.println("请输入新货物的价格");
f.jg = sc.nextInt();
System.out.println("请输入新货物的库存");
f.kc= sc.nextInt();
System.out.println("修改成功");
return;
}
} System.out.println("无此商品");
}
public static void tc() {
System.out.println("您已退出!!!");