package 课堂笔记;
import java.util.Scanner;
public class PP {
YY chen = new YY();
Scanner scanner = new Scanner(System.in);
public void ja(){
JJ xiaoMi9 = new JJ();
xiaoMi9.name = "小米9";
xiaoMi9.liang = 0;
xiaoMi9.jia = 2799;
xiaoMi9.shu = 60;
JJ xiaoMi8 = new JJ();
xiaoMi8.shu = 40;
xiaoMi8.name = "小米8";
xiaoMi8.jia = 2049;
xiaoMi8.liang = 0;
JJ xiaoMi7 = new JJ();
xiaoMi7.liang = 0;
xiaoMi7.name = "小米7";
xiaoMi7.jia = 699;
xiaoMi7.shu = 80;
JJ xiaoMi6 = new JJ();
xiaoMi6.shu = 100;
xiaoMi6.name = "小米6";
xiaoMi6.jia = 749;
xiaoMi6.liang = 0;
chen.JYY[0] = xiaoMi9;
chen.JYY[1] = xiaoMi8;
chen.JYY[2] = xiaoMi7;
chen.JYY[3] = xiaoMi6;
}
public void startMenu() {
boolean flag = true;//是否继续
do {
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("5. 商品销售排行耪");
System.out.println("6. 退出");
System.out.println("-------------------------------------");
System.out.println("请选择执行的操作;");
int wo = scanner.nextByte();
switch (wo){
case 1:
System.out.println("查看商品信息");
Jao();
break;
case 2:
System.out.println("新增商品信息");
she();
break;
case 3:
System.out.println("删除商品信息");
ye();
break;
case 4:
System.out.println("卖出商品");
oo();
break;
case 5:
System.out.println("商品销售排行");
ppp();
break;
case 6:
System.out.println("谢谢使用!");
flag = false;
break;
default:
System.out.println("输入不符合要求请重新输入!");
break;
}
} while (flag);
}
public static void main(String[] args) {
PP JPY = new PP(); // 入口
JPY.ja();
JPY.startMenu(); // 进入一段代码的入口
}
public void Jao(){
System.out.println("编号\t名称\t价格\t库存\t售出");
for (int i= 0 ; i < chen.JYY.length; i++ ){
if (chen.JYY[i]!=null){
chen.JYY[i].jia(i+1);
}
}
}
public void she(){
System.out.println("请输入商品名称;");
String name = scanner.next();
System.out.println("请输入商品价格:");
int jia = scanner.nextByte();
System.out.println("请输入库存:");
int shu = scanner.nextByte();
JJ ji = new JJ();
ji.jia = jia;
ji.shu = shu;
ji.name = name;
ji.liang = 0;
for (int i = 0; i < chen.JYY.length; i++){
if (chen.JYY[i]==null){
chen.JYY[i]=ji;
break;
}
}
}
public void ye(){
System.out.println("请输入商品编号:");
boolean flag = true;//是否删除成功
int kk = scanner.nextByte();
for (int i = 0 ; i if (chen.JYY[i]!=null&&(i+1)==kk){ int j = i; while (chen.JYY[j+1]!=null){ chen.JYY[j]=chen.JYY[j+1]; j++; } chen.JYY[j]=null; flag = true; break; }else { flag =false; } } if (flag){ System.out.println("删除成功!"); }else { System.out.println("删除失败,请重新操作!"); } } public void oo(){ System.out.println("请输入你要卖出的商品名称;"); String name = scanner.next(); for (int i = 0; i< chen.JYY.length;i++){ if (chen.JYY[i]!=null&&chen.JYY[i].name.equals(name)){ System.out.println("请输入你要售卖的数量:"); int shou = scanner.nextInt(); chen.JYY[i].shu = chen.JYY[i].shu - shou ; chen.JYY[i].liang = chen.JYY[i].liang + shou; } System.out.println("售卖成功"); break; } } public void ppp(){ for (int i = 0 ; i< chen.JYY.length-1;i++){ for (int j = 0; j< chen.JYY.length-i-1;j++){ if (chen.JYY[j]!=null&&chen.JYY[j+1]!=null){ if (chen.JYY[j].shu JJ ok = chen.JYY[j]; chen.JYY[j] = chen.JYY[j+1]; chen.JYY[j+1] = ok; } } } } System.out.println("排行榜"); System.out.println("名次\t销售数量\t商品名称"); for (int i= 0;i if (chen.JYY[i]!=null){ System.out.println(i+1+"\t"+chen.JYY[i].liang+"\t"+chen.JYY[i].name); } } } }