https://download.csdn.net/download/shui_jin_shan/10798218
上面是我放的代码地址:
下面我的welcome的代码:
/**
*
*/
package supermarket;
import java.util.Scanner;
/**
* @author Administrator 欢迎界面
*/
public class Welcome {
public static void main(String[] args) {
Supermarket supermarket = new Supermarket("大润发");
Shelf[] shelfs = new Shelf[3];// 货架3个
Goods[] goods = new Goods[5];// 每个货架的商品数最大5
int[] countOfShelf = new int[3];// 統計每個货架的商品数
shelfs[0] = new Shelf("食物", 0);
shelfs[1] = new Shelf("衣物", 1);
shelfs[2] = new Shelf("日用品", 2);
goods[0] = new Goods(0, "薯片", "乐事", 99, "2018年11月20日", 4.5, 3.5);
goods[1] = new Goods(1, "方便面", "康师傅", 99, "2018年11月20日", 3.5, 2.5);
countOfShelf[0] = 2;
shelfs[0].setGoods(goods);
goods = new Goods[5];
goods[0] = new Goods(0, "卫衣", "美特斯邦威", 50, "2018年11月20日", 150.0, 130.0);
goods[1] = new Goods(1, "运动裤", "耐克", 50, "2018年11月20日", 140.0, 120.0);
countOfShelf[1] = 2;
shelfs[1].setGoods(goods);
goods = new Goods[5];
goods[0] = new Goods(0, "香皂", "舒肤佳", 50, "2018年11月20日", 10.0, 8.0);
goods[1] = new Goods(1, "洗发露", "海飞丝", 50, "2018年11月20日", 15.0, 12.0);
countOfShelf[2] = 2;
shelfs[2].setGoods(goods);
supermarket.setShelfs(shelfs);
// 初始化超市商品-------------------------------------------------------------------------------------
while (true) {
// 先初始化使用的变量
boolean isExit = false;// 判断是否退出
int key = -1;// 选项输入初始化
int cardId = 0;// 会员卡号初始化
int credit = 0;// 会员积分初始化
double totalCost = 0;// 总花费初始化
Goods[] goodssOfNew = null;// 购买选项货物列表初始化
double priceOfGoods = 0;// 商品价格初始化
int idOfGoods = -1;// 商品编号初始化
int countOfBuy = 0;// 购买数量初始化
int getCountOfGoods = 0;// 货架物品数量初始化
// ----------------------------------------------------------------------------------------
System.out.println("欢迎进入大润发超市管理系统界面");
System.out.println("--------------------");
System.out.println("选项\t项目名称");
System.out.println("1.\t商品管理");
System.out.println("2.\t员工管理");
System.out.println("3.\t会员管理");
System.out.println("4.\t购买操作");
System.out.println("按其他键退出");
System.out.println("--------------------");
Scanner input = new Scanner(System.in);
System.out.println("請輸入选择:");
switch (input.nextInt()) {
case 1:
while (true) {
System.out.println("选项\t内容");
System.out.println("-------------------");
System.out.println("1.\t商品添加");
System.out.println("2.\t商品删除");
System.out.println("3.\t商品查询");
System.out.println("or 按任意键退出");
System.out.println("-------------------");
System.out.println("请输入:");
key = input.nextInt();
switch (key) {
case 1:
break;
case 2:
break;
case 3:
break;
default:
isExit = true;
break;
}
if (isExit) {
break;
}
}
break;
case 2:
break;
case 3:
while (true) {
System.out.println("选项\t内容");
System.out.println("-------------------");
System.out.println("1.\t查看会员信息");
System.out.println("2.\t添加会员");
System.out.println("3.\t删除会员");
System.out.println("or 按任意键退出");
System.out.println("-------------------");
System.out.println("请输入:");
key = input.nextInt();
switch (key) {
case 1:
System.out.println("请输入想要查看的会员卡号");
cardId = input.nextInt();
Card.query(cardId);
break;
case 2:
Card.add();
break;
case 3:
System.out.println("请输入需要删除的会员卡号");
cardId = input.nextInt();
Card.delete(cardId);
break;
default:
isExit = true;
break;
}
if (isExit) {
break;
}
}
break;
case 4:
while (true) {
System.out.println("欢迎光临" + supermarket.getmName());
System.out.println("货架列表如下:");
System.out.println("货架编号\t货架类型");
Shelf[] she = supermarket.getShelfs();
for (int i = 0; i < she.length; i++) {
System.out.println(she[i].getShelfId() + "\t" + she[i].getShelfName());
}
System.out.println("请选择货架编号:");
key = input.nextInt();
switch (key) {
case 0:
System.out.println("有以下商品:");
System.out.println("商品编号\t商品名称\t商品价格");
goodssOfNew = she[0].getGoods();
getCountOfGoods = countOfShelf[0];
for (int i = 0; i < getCountOfGoods; i++) {
System.out.println(goodssOfNew[i].getgId() + "\t" + goodssOfNew[i].getBrand()
+ goodssOfNew[i].getgName() + "\t" + goodssOfNew[i].getgPrice());
}
System.out.println("请输入商品编号:");
idOfGoods = input.nextInt();
for (int i = 0; i < getCountOfGoods; i++) {
if (idOfGoods == goodssOfNew[i].getgId()) {
priceOfGoods = goodssOfNew[i].getgPrice();
}
}
System.out.println("请输入数量:");
countOfBuy = input.nextInt();
totalCost += priceOfGoods * countOfBuy;
break;
case 1:
System.out.println("有以下商品:");
System.out.println("商品编号\t商品名称\t商品价格");
goodssOfNew = she[1].getGoods();
getCountOfGoods = countOfShelf[1];
for (int i = 0; i < getCountOfGoods; i++) {
System.out.println(goodssOfNew[i].getgId() + "\t" + goodssOfNew[i].getBrand()
+ goodssOfNew[i].getgName() + "\t" + goodssOfNew[i].getgPrice());
}
System.out.println("请输入商品编号:");
idOfGoods = input.nextInt();
for (int i = 0; i < getCountOfGoods; i++) {
if (idOfGoods == goodssOfNew[i].getgId()) {
priceOfGoods = goodssOfNew[i].getgPrice();
}
}
System.out.println("请输入数量:");
countOfBuy = input.nextInt();
totalCost += priceOfGoods * countOfBuy;
break;
case 2:
System.out.println("有以下商品:");
System.out.println("商品编号\t商品名称\t商品价格");
goodssOfNew = she[2].getGoods();
getCountOfGoods = countOfShelf[2];
for (int i = 0; i < getCountOfGoods; i++) {
System.out.println(goodssOfNew[i].getgId() + "\t" + goodssOfNew[i].getBrand()
+ goodssOfNew[i].getgName() + "\t" + goodssOfNew[i].getgPrice());
}
System.out.println("请输入商品编号:");
idOfGoods = input.nextInt();
for (int i = 0; i < getCountOfGoods; i++) {
if (idOfGoods == goodssOfNew[i].getgId()) {
priceOfGoods = goodssOfNew[i].getgPrice();
}
}
System.out.println("请输入数量:");
countOfBuy = input.nextInt();
totalCost += priceOfGoods * countOfBuy;
break;
default:
isExit = true;
break;
}
System.out.println("请输入您的会员卡号,没有请按0");
key = input.nextInt();
for (int i = 0; i < Card.numOfCards; i++) {
if (key == 0) {
break;
}
if (key == Card.cards[i].getCardId()) {
cardId = key;
break;
}
}
System.out.println("您总共消费 " + totalCost + " 元");
if (cardId != 0) {
Card.setCredit((int) totalCost, cardId);
credit = Card.getCredit(cardId);
System.out.println("您当前拥有积分 " + credit);
}
System.out.println("是否要继续购买?继续请按1,结账请按2");
key = input.nextInt();
if (key == 2) {
System.out.println("您需要付" + (totalCost - credit / 100) + " 元");
credit -= credit / 100 * 100;
Card.setCredit(credit, cardId);
if (cardId != 0) {
System.out.println("您还剩积分 " + Card.getCredit(cardId));
}
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
isExit = true;
}
if (isExit) {
break;
}
}
break;
default:
System.exit(0);
}
}
}
}