您的位置:首页 > 其它

我行我素购物管理系统(部分功能)

2014-04-15 19:30 656 查看
import java.text.DecimalFormat;
import java.util.Scanner;

/**
* 多个客户登录(已经成功)
* 用户密码修改已经完成
* 购物完成
* 客户信息管理完成
* 还可以完善
* @author Administrator
*
*/
public class Shopping {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String[] name = new String[3];
String[] psw = new String[3];
name[0] = "admin";
name[1] = "admin1";
name[2] = "admin2";
psw[0] = "admin";
psw[1] = "admin1";
psw[2] = "admin2";
//定义客户信息数组
//客户编号
String []id=new String[3];
id[0]="1001";
id[1]="1002";
id[2]="1003";
//客户姓名
String[] customerName=new String[3];
customerName[0]="小猫";
customerName[1]="小狗";
customerName[2]="小马";
//客户生日
String []birthday=new String[3];
birthday[0]="1993-01-19";
birthday[1]="1992-01-19";
birthday[2]="1991-01-19";
//客户积分
int[]score=new int[3];
score[0]=1000;
score[1]=2000;
score[2]=3000;
int j = 0;// 定义一个局部变量,方便取值(修改密码要用)
// 控制小数点位数为一位
DecimalFormat df = new DecimalFormat(
"#.0");

yiji: while (true) {
System.out.println("\t\t\t欢迎使用我行我素购物管理系统");
System.out
.println("**************************************************************");
System.out.println("\n\t\t\t1.登录系统");
System.out.println("\n\t\t\t2.更改管理员密码");
System.out.println("\n\t\t\t3.退出");

System.out
.println("**************************************************************");
qiji: while (true) {
System.out.println("请输入你的选择:");
String choice = input.next();
if (choice.equals("1")) {
System.out
.println("--------------------------------------------------------------");
// 验证用户名和密码
int loginIndex = 0;
erji: while (true) {
System.out.println("请输入用户名:");
String userName = input.next();
System.out.println("请输入密码:");
String password = input.next();
// 加一个循环便于多个客户登录系统
for (j = 0; j < psw.length; j++) {
if (name[j].equals(userName)
&& psw[j].equals(password)) {
System.out.println("成功登录");
break erji;

}
}

loginIndex++;
if (loginIndex > 2) {
System.out.println("你的机会已经用完了!警察叔叔会来找你的");
System.exit(1);
}

System.out.println("对不起,你的用户名或者密码有误,你还有"
+ (3 - loginIndex) + "次机会");
continue erji;

}// 三级循环

System.out.println("----------------------登录中-------------");
erji: while (true) {
System.out
.println("**************************************************************");
System.out.println("\t\t\t1,客户信息管理");
System.out.println("\t\t\t2,购物结算");
System.out.println("\t\t\t3,真情回馈");
System.out.println("\t\t\t4,返回上一级");
System.out
.println("**************************************************************");
baji: while (true) {
System.out.println("请输入你的选择:");
choice = input.next();
// 对输入不存在的编号进行判断并进行处理
if (!choice.equals("1")&&(!choice.equals("2"))&&(!choice.equals("3")&&(!choice.equals("4")))) {
System.out.println("对不起,你的选择有误,请重新输入:");
continue baji;
}
if (choice.equals("1")) {
sanji: while (true) {
System.out.println("我行我素购物管理系统>客户信息管理");
System.out
.println("**************************************************************");
System.out.println("\t\t\t1,显示所有客户信息");
System.out.println("\t\t\t2,添加客户信息");
System.out.println("\t\t\t3,修改客户信息");
System.out.println("\t\t\t4,查询客户信息");
System.out.println("\t\t\t5,返回上一级");
System.out
.println("**************************************************************");
jiuji: while (true) {
System.out.println("请输入你的选择:");
choice = input.next();
if (!choice.equals("1")&&(!choice.equals("2"))&&(!choice.equals("3")&&(!choice.equals("4")&&(!choice.equals("5"))))) {
System.out
.println("对不起,你的选择有误,请重新输入:");
continue jiuji;
}

if (choice.equals("1")) {
System.out.println("显示客户信息");

System.out.println("--------------------------------------------------------------");
System.out.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");
for (int i = 0; i < score.length; i++) {
System.out.println(id[i]+"\t\t\t"+customerName[i]+"\t\t\t"+birthday[i]+"\t"+score[i]);
}//for循环
System.out.println("--------------------------------------------------------------");	System.out.println("按任意键继续:");
String free = input.next();
continue sanji;
}
if (choice.equals("2")) {
System.out.println("添加客户信息");
// 功能暂时不做
System.out.println("该功能正在升级中!");
System.out.println("按任意键继续:");
String free = input.next();
continue sanji;
}
if (choice.equals("3")) {
System.out.println("修改客户信息");
update:
while(true){
System.out.println("请输入你要修改的客户编号:");
String idNum=input.next();
int i=0;
int newIndex=0;
test:
for (  i= 0; i < score.length; i++) {
if(idNum.equals(id[i])){
break;
}else{
newIndex++;
}}//
if(newIndex==score.length){
System.out.println("查无此人,请重新输入:");
continue update;
}

System.out.println(id[i]+"\t\t\t"+customerName[i]+"\t\t\t"+birthday[i]+"\t"+score[i]);
System.out.println("请输入你要修改的内容:1.姓名\t\t2.客户积分");
choice:
while(true){
System.out.println("请输入你的选择:");
choice=input.next();
if(choice.equals("1")){
System.out.println("请输入新的客户名称:");
String newName=input.next();
System.out
.println("原姓名:"+customerName[i]);
customerName[i]=newName;
System.out.println("修改成功");
break;
}
if(choice.equals("2")){
System.out.println("请输入新的客户积分:");
int newScore=input.nextInt();

score[i]=newScore;
System.out.println("修改成功");
break ;
}
if(!(choice.equals("1"))&&!(choice.equals("2"))){
System.out.println("对不起,输入有误,请重新输入:");
continue choice;
}
}

// 功能暂时不做
System.out.println("该功能正在升级中!");
System.out.println("按任意键继续:");
String free = input.next();
continue sanji;
}//update循环
}
if (choice.equals("4")) {
System.out.println("查询客户信息");
// 功能暂时不做
query:
while(true){
System.out.println("请输入你要查询的客户编号:");
String idNum=input.next();
int i=0;
int index=0;
for ( i = 0; i < score.length; i++) {
if(idNum.equals(id[i])){
break;
}else{
index++;
}
}//for循环
if(index==score.length){
System.out.println("查询此人:");
continue query;
}
//输出信息
System.out.println(id[i]+"\t\t\t"+customerName[i]+"\t\t\t"+birthday[i]+"\t"+score[i]);
System.out.println("按任意键继续:");
String free = input.next();
continue sanji;
}//query
}

if (choice.equals("5")) {
System.out.println("返回到第二级菜单");
continue erji;// 这是是重大发现
}
}// 九级循环
}// 三层循环
}
if (choice.equals("2")) {
System.out.println("购物结算");
System.out
.println("--------------------------------------------------------------");
siji: while (true) {
System.out.println("欢迎进入购物系统");
System.out.println("请输入你的客户编号:");// 暂时不做查询出来,只是形式
String num = input.next();
System.out.println("商城现有商品如下:");
System.out.println("商品编号\t\t商品名称\t\t商品价格");
System.out.println("1\t\t\t云南白药\t\t¥18.00");
System.out
.println("2\t\t\t小米手机\t\t¥1999.00");
System.out
.println("3\t\t\t汽车模型\t\t¥350.00");
System.out
.println("4\t\t\t坦克模型\t\t¥480.00");
System.out
.println("5\t\t\t联想电脑\t\t¥4000.00");

// 定义一些共有的变量
String goods = "";// 商品名称
double price = 0;// 商品价格
double discount = 0.85;// 折扣
int count=0;

// 定义总价格计算公式
double total = count * price ;
int money;
liuji: while (true) {

String answer="y";
while("y".equals(answer)){
System.out.println("请输入你要购买的商品编号:");
int number = input.nextInt();
// 对商品编号进行判断
if (number > 5) {
System.out
.println("你输入的商品编号不存在,请重新输入购买商品:");
continue liuji;
}

System.out.println("请输入你要购买的产品数量:");
count = input.nextInt();
switch (number) {
case 1:
goods = "云南白药";
price = 18.00;
break;
case 2:
goods = "小米手机";
price = 1999.00;
break;
case 3:
goods = "汽车模型";
price = 350.00;
break;
case 4:
goods = "坦克模型";
price = 480.00;
break;
case 5:
goods = "联想电脑";
price = 4000.00;
break;
default:

}

// 通过之前的选择输入一下商品信息
System.out
.println("--------------------------------------------------------------");

System.out.println("尊敬的用户:小猫");
System.out
.println("产品名称\t\t产品单价\t\t购买数量\t\t产品总价");
System.out.println(goods + "\t\t¥"
+ price + "\t\t\t" + count
+ "\t\t" + count * price);
total+=price*count;
System.out.println("是否要继续?y/n");
answer=input.next();

}//是否购买的循环
System.out.println("你购买的商品总价为:" +total
);
System.out.println("按你现在的积分,你的折扣是"
+ discount);
System.out.println("你的应付金额为:¥"
+ df.format(total*discount));
System.out.println("请付款:");
money = input.nextInt();
// 加一个循环语句,避免出现选择不能使用的功能
while (money < total*discount) {
System.out
.println("对不起,你的付款少于应付金额,无法好好做朋友了!请重新输入:");
money = input.nextInt();
}
System.out.println("付款成功!");
System.out.println("找零:"
+ df.format(money - total*discount));
System.out.println("谢谢回顾,欢迎下次光临!");
System.out
.println("--------------------------------------------------------------");

// 功能暂时不做
System.out.println("按任意键继续:");
String free = input.next();
continue erji;
}// 六级循环

}// 四级循环
}

if (choice.equals("3")) {
System.out.println("真情回馈");
System.out
.println("--------------------------------------------------------------");
wuji: while (true) {
System.out.println("我行我素购物管理系统>真情回馈");
System.out
.println("***********************************");
System.out.println("\t\t\t1,幸运大发送");
System.out.println("\t\t\t2,幸运抽奖");
System.out.println("\t\t\t3,生日问候");
System.out.println("\t\t\t4,返回上一级");
System.out
.println("**************************************************************");
shiji: while (true) {
System.out.println("请输入你的选择:");
choice = input.next();
if (choice.equals("1")) {
System.out.println("幸运大放送");
// 只做个形式
System.out.println("积分最高的客户是:");
System.out
.println("------------------------------------");
System.out
.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");
System.out
.println("1001\t\t\t小猫\t\t\t1992-01-19\t2000");
System.out
.println("恭喜以上客户,获得一个价值为¥5800.00的Iphone5s");
System.out
.println("--------------------------------------------------------------");
System.out.println("按任意键继续:");
String free = input.next();
continue wuji;
}
if (choice.equals("2")) {
System.out.println("幸运抽奖");
// 只做个形式
System.out.println("幸运客户是:");
System.out
.println("--------------------------------------------------------------");
System.out
.println("客户编号\t\t客户姓名\t\t客户生日\t\t客户积分");
System.out
.println("1001\t\t\t小猫\t\t\t1992-01-19\t2000");
System.out
.println("恭喜以上客户,获得一个价值为¥5800.00的Iphone5s");
System.out
.println("--------------------------------------------------------------");
System.out.println("按任意键继续:");
String free = input.next();
continue wuji;
}
if (choice.equals("3")) {
System.out.println("生日问候");
System.out
.println("对不起,今天没有过生日的客户!");
System.out.println("按任意键继续:");
String free = input.next();
continue wuji;
}
if (choice.equals("4")) {
System.out.println("返回到第二级菜单");
continue erji;// 返回到二级菜单
}

System.out
.println("--------------------------------------------------------------");
}// 十级循环
}// 五级循环
}

if (choice.equals("4")) {
System.out.println("返回第一级菜单");
continue yiji;
}
}// 八级循环
}// 二层循环

}// 条件一

if (choice.equals("2")) {
System.out.println("--------------------------------------------------------------");
int loginIndex = 0;
lang: while (true) {
System.out.println("请输入用户名:");
String userName = input.next();
System.out.println("请输入密码:");
String password = input.next();
for (j = 0; j < psw.length; j++) {
if (name[j].equals(userName)
&& psw[j].equals(password)) {
//System.out.println("成功登录");
break lang;
}
}

loginIndex++;
if (loginIndex > 2) {
System.out.println("你的机会已经用完了!警察叔叔会来找你的");
System.exit(1);
}

System.out.println("对不起,你的用户名或者密码有误,你还有"
+ (3 - loginIndex) + "次机会");
continue lang;
//System.out.println("--------------------------------------------------------------");
}//lang循环
System.out.println("---------登录中---------");
System.out.println("第" + (j+1) + "用户登录成功");
boolean isRepeat = true;
int repeatNum = 0;
dangqian: while (isRepeat) {
System.out.println("请输入新的密码");
String newPassword = input.next();
System.out.println("再次输入新的密码:");
String RepeatPsw = input.next();
if (!newPassword.equals(RepeatPsw)) {
repeatNum++;

if (repeatNum > 2) {
System.out.println("你已经没有机会了!");
System.exit(1);
} else {
System.out.println("你的两次密码不一致,你还有"
+ (3 - repeatNum) + "次机会,请慎重输入:");
continue dangqian;
}
}else {
System.out.println("修改成功");
psw[j] = RepeatPsw;

System.out.println("按任意键继续");
String free = input.next();
continue yiji;// 用这个语句继续第一个循环

}

}//dangqian循环
}//条件二

if (choice.equals("3")) {
System.out.println("系统即将退出....");
System.exit(1);
}
if(!choice.equals("1")&&(!choice.equals("2"))&&(!choice.equals("3"))){
System.out.println("你的输入有误,请重新输入:");
continue qiji;
}
}// 二级循环

}// 一级循环

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: