仿写的购物系统 有些缺点 见笑了

------- <a href="http://edu.csdn.net/heima" target="blank">android培训</a>、<a href="http://edu.csdn.net/heima" target="blank">java培训</a>、期待与您交流! ----------
//验证管理员的类

package cn.itcast;

import java.util.Scanner;

/**
 * 验证管理员登录
 * 
 * @author Administrator
 * 
 */
public class VerifyEqual {

	public VerifyEqual() {
	}

	public boolean verify(String s, String s1) {
		System.out.print("请输入用户名:");
		Scanner scanner = new Scanner(System.in);
		String s2 = scanner.next();
		System.out.print("请输入密码:");
		scanner = new Scanner(System.in);
		String s3 = scanner.next();
		return s2.equals(s) && s1.equals(s3);
	}
}


 

 

//这个是卖的物品

package cn.itcast;

/**
 * 初始化数据
 * 
 * @author Administrator
 * 
 */
public class Data {

	public Data() {
		goodsName = new String[50];
		goodsPrice = new double[50];
		custNo = new int[100];
		custBirth = new String[100];
		custScore = new int[100];
		manager = new Manager();
	}

	public void ini() {
		goodsName[0] = "addidas运动鞋";
		goodsPrice[0] = 880D;
		goodsName[1] = "Kappa网球裙";
		goodsPrice[1] = 200D;
		goodsName[2] = "网球拍";
		goodsPrice[2] = 780D;
		goodsName[3] = "addidasT恤";
		goodsPrice[3] = 420.77999999999997D;
		goodsName[4] = "Nike运动鞋";
		goodsPrice[4] = 900D;
		goodsName[5] = "Kappa网球";
		goodsPrice[5] = 45D;
		goodsName[6] = "KappaT恤";
		goodsPrice[6] = 245D;
		custNo[0] = 1900;
		custBirth[0] = "08/05";
		custScore[0] = 2000;
		custNo[1] = 1711;
		custBirth[1] = "07/13";
		custScore[1] = 4000;
		custNo[2] = 1623;
		custBirth[2] = "06/26";
		custScore[2] = 5000;
		custNo[3] = 1545;
		custBirth[3] = "04/08";
		custScore[3] = 2200;
		custNo[4] = 1464;
		custBirth[4] = "08/16";
		custScore[4] = 1000;
		custNo[5] = 1372;
		custBirth[5] = "12/23";
		custScore[5] = 3000;
		custNo[6] = 1286;
		custBirth[6] = "12/21";
		custScore[6] = 10080;
	}

	public String goodsName[];
	public double goodsPrice[];
	public int custNo[];
	public String custBirth[];
	public int custScore[];
	public Manager manager;
}


//礼物类

 

package cn.itcast;

/**
 * 礼物类
 */
public class Gift {

	public Gift() {
	}

	public String toString() {
		return (new StringBuilder()).append("一个价值¥").append(price).append("的")
				.append(name).toString();
	}

	public String name;
	public double price;
}


 //管理礼物类

package cn.itcast;

import java.util.Scanner;

/**
 * 礼物管理类
 * 
 * @author Administrator
 * 
 */
public class GiftManagement {

	public GiftManagement() {
	}

	public void setData(String as[], double ad[], int ai[], String as1[],
			int ai1[]) {
		goodsName = as;
		goodsPrice = ad;
		custNo = ai;
		custBirth = as1;
		custScore = ai1;
	}

	public void returnLastMenu() {
		System.out.print("\n\n请按'n'返回上一级菜单:");
		Scanner scanner = new Scanner(System.in);
		boolean flag = true;
		do
			if (scanner.next().equals("n")) {
				Menu menu = new Menu();
				menu.setData(goodsName, goodsPrice, custNo, custBirth,
						custScore);
				menu.showSendGMenu();
			} else {
				System.out.print("输入错误, 请重新'n'返回上一级菜单:");
				flag = false;
			}
		while (!flag);
	}

	public void sendBirthCust() {
		System.out.println("购物管理系统 > 生日问候\n\n");
		System.out.print("请输入今天的日期(月/日<用两位表示>):");
		Scanner scanner = new Scanner(System.in);
		String s = scanner.next();
		System.out.println(s);
		String s1 = "";
		boolean flag = false;
		for (int i = 0; i < custBirth.length; i++)
			if (custBirth[i] != null && custBirth[i].equals(s)) {
				s1 = (new StringBuilder()).append(s1).append(custNo[i]).append(
						"\n").toString();
				flag = true;
			}

		if (flag) {
			System.out.println("过生日的会员是:");
			System.out.println(s1);
			System.out.println("恭喜!获赠MP3一个!");
		} else {
			System.out.println("今天没有过生日的会员!");
		}
		returnLastMenu();
	}

	public void sendLuckyCust() {
		System.out.println("购物管理系统 > 幸运抽奖\n\n");
		System.out.print("是否开始(y/n):");
		Scanner scanner = new Scanner(System.in);
		if (scanner.next().equals("y")) {
			int i = (int) (Math.random() * 10D);
			boolean flag = false;
			String s = "";
			for (int k = 0; k < custNo.length && custNo[k] != 0; k++) {
				int j = (custNo[k] / 100) % 10;
				if (j == i) {
					s = (new StringBuilder()).append(s).append(custNo[k])
							.append("\t").toString();
					flag = true;
				}
			}

			if (flag)
				System.out.println((new StringBuilder()).append("幸运客户获赠MP3:")
						.append(s).toString());
			else
				System.out.println("无幸运客户。");
		}
		returnLastMenu();
	}

	public void sendGoldenCust() {
		System.out.println("购物管理系统 > 幸运大放送\n\n");
		int i = 0;
		int j = custScore[0];
		for (int k = 0; k < custScore.length && custScore[k] != 0; k++)
			if (custScore[k] > j) {
				j = custScore[k];
				i = k;
			}

		System.out.println((new StringBuilder()).append("具有最高积分的会员是: ").append(
				custNo[i]).append("\t").append(custBirth[i]).append("\t")
				.append(custScore[i]).toString());
		Gift gift = new Gift();
		gift.name = "苹果笔记本电脑";
		gift.price = 12000D;
		System.out.print("恭喜!获赠礼品: ");
		System.out.println(gift);
		returnLastMenu();
	}

	public String goodsName[];
	public double goodsPrice[];
	public int custNo[];
	public String custBirth[];
	public int custScore[];
}


//管理员类

package cn.itcast;

/**
 * 管理员类
 * 
 * @author Administrator
 * 
 */
public class Manager {

	public Manager() {
		username = "itcast";
		password = "itcast";
	}

	public String username;
	public String password;
}


//页面类

package cn.itcast;

import java.util.Scanner;

/**
 * 页面类
 * 
 * @author Administrator
 * 
 */
public class Menu {

	public Menu() {
	}

	public void setData(String as[], double ad[], int ai[], String as1[],
			int ai1[]) {
		goodsName = as;
		goodsPrice = ad;
		custNo = ai;
		custBirth = as1;
		custScore = ai1;
	}

	public void showLoginMenu() {
		System.out.println("\n\n\t\t\t    欢迎使用itcast购物管理系统1.0版\n\n");
		System.out
				.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
		System.out.println("\t\t\t\t 1. 登 录 系 统\n\n");
		System.out.println("\t\t\t\t 2. 更 改 管 理 员 密 码\n\n");
		System.out.println("\t\t\t\t 3. 退 出\n\n");
		System.out
				.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
		System.out.print("请选择,输入数字:");
	}

	public void showMainMenu() {
		System.out.println("\n\n\t\t\t\t欢迎使用购物管理系统\n");
		System.out
				.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
		System.out.println("\t\t\t\t 1. 客 户 信 息 管 理\n");
		System.out.println("\t\t\t\t 2. 购 物 结 算\n");
		System.out.println("\t\t\t\t 3. 真 情 回 馈\n");
		System.out.println("\t\t\t\t 4. 注 销\n");
		System.out
				.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
		System.out.print("请选择,输入数字:");
		Scanner scanner = new Scanner(System.in);
		boolean flag = false;
		do {
			String s = scanner.next();
			if (s.equals("1")) {
				showCustMMenu();
				break;
			}
			if (s.equals("2")) {
				Pay pay = new Pay();
				pay
						.setData(goodsName, goodsPrice, custNo, custBirth,
								custScore);
				pay.calcPrice();
				break;
			}
			if (s.equals("3")) {
				showSendGMenu();
				break;
			}
			if (s.equals("4")) {
				showLoginMenu();
				break;
			}
			System.out.print("输入错误,请重新输入数字:");
			flag = false;
		} while (!flag);
	}

	public void showCustMMenu() {
		System.out.println("购物管理系统 > 客户信息管理\n");
		System.out
				.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
		System.out.println("\t\t\t\t 1. 显 示 所 有 客 户 信 息\n");
		System.out.println("\t\t\t\t 2. 添 加 客 户 信 息\n");
		System.out.println("\t\t\t\t 3. 修 改 客 户 信 息\n");
		System.out.println("\t\t\t\t 4. 查 询 客 户 信 息\n");
		System.out
				.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
		System.out.print("请选择,输入数字或按'n'返回上一级菜单:");
		Scanner scanner = new Scanner(System.in);
		boolean flag = true;
		do {
			CustManagement custmanagement = new CustManagement();
			custmanagement.setData(goodsName, goodsPrice, custNo, custBirth,
					custScore);
			String s = scanner.next();
			if (s.equals("1")) {
				custmanagement.show();
				break;
			}
			if (s.equals("2")) {
				custmanagement.add();
				break;
			}
			if (s.equals("3")) {
				custmanagement.modify();
				break;
			}
			if (s.equals("4")) {
				custmanagement.search();
				break;
			}
			if (s.equals("n")) {
				showMainMenu();
				break;
			}
			System.out.println("输入错误, 请重新输入数字:");
			flag = false;
		} while (!flag);
	}

	public void showSendGMenu() {
		System.out.println("购物管理系统 > 真情回馈\n");
		System.out
				.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
		System.out.println("\t\t\t\t 1. 幸 运 大 放 送\n");
		System.out.println("\t\t\t\t 2. 幸 运 抽 奖\n");
		System.out.println("\t\t\t\t 3. 生 日 问 候\n");
		System.out
				.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
		System.out.print("请选择,输入数字或按'n'返回上一级菜单:");
		Scanner scanner = new Scanner(System.in);
		boolean flag = true;
		GiftManagement giftmanagement = new GiftManagement();
		giftmanagement.setData(goodsName, goodsPrice, custNo, custBirth,
				custScore);
		do {
			String s = scanner.next();
			if (s.equals("1")) {
				giftmanagement.sendGoldenCust();
				break;
			}
			if (s.equals("2")) {
				giftmanagement.sendLuckyCust();
				break;
			}
			if (s.equals("3")) {
				giftmanagement.sendBirthCust();
				break;
			}
			if (s.equals("n")) {
				showMainMenu();
				break;
			}
			System.out.println("输入错误, 请重新输入数字:");
			flag = false;
		} while (!flag);
	}

	public String goodsName[];
	public double goodsPrice[];
	public int custNo[];
	public String custBirth[];
	public int custScore[];
}

//购物类

package cn.itcast;

import java.util.Scanner;

/**
 * 购物付款
 * 
 * @author Administrator
 * 
 */
public class Pay {

	public Pay() {
	}

	public void setData(String as[], double ad[], int ai[], String as1[],
			int ai1[]) {
		goodsName = as;
		goodsPrice = ad;
		custNo = ai;
		custBirth = as1;
		custScore = ai1;
	}

	public double getDiscount(int i, int ai[], int ai1[]) {
		int j = -1;
		int k = 0;
		do {
			if (k >= ai.length)
				break;
			if (i == ai[k]) {
				j = k;
				break;
			}
			k++;
		} while (true);
		double d;
		if (ai1[j] < 1000)
			d = 0.94999999999999996D;
		else if (1000 <= ai1[j] && ai1[j] < 2000)
			d = 0.90000000000000002D;
		else if (2000 <= ai1[j] && ai1[j] < 3000)
			d = 0.84999999999999998D;
		else if (3000 <= ai1[j] && ai1[j] < 4000)
			d = 0.80000000000000004D;
		else if (4000 <= ai1[j] && ai1[j] < 6000)
			d = 0.75D;
		else if (6000 <= ai1[j] && ai1[j] < 8000)
			d = 0.69999999999999996D;
		else
			d = 0.59999999999999998D;
		return d;
	}

	public void calcPrice() {
		String s2 = "";
		double d1 = 0.0D;
		double d2 = 0.0D;
		System.out.println("购物管理系统 > 购物结算\n\n");
		System.out.println("*************************************");
		System.out.println("请选择购买的商品编号:");
		int l = 0;
		double d4 = 0;
		for (; l < goodsName.length && goodsName[l] != null; l++) {
			d4++;
			System.out.println((new StringBuilder()).append(d4).append(": ")
					.append(goodsName[l]).append("\t").toString());
		}

		System.out.println("*************************************\n");
		Scanner scanner = new Scanner(System.in);
		System.out.print("\t请输入会员号:");
		int i = scanner.nextInt();
		d4 = getDiscount(i, custNo, custScore);
		String s1;
		do {
			System.out.print("\t请输入商品编号:");
			int j = scanner.nextInt();
			System.out.print("\t请输入数目:");
			int k = scanner.nextInt();
			double d = goodsPrice[j - 1];
			String s = goodsName[j - 1];
			d1 += d * (double) k;
			s2 = (new StringBuilder()).append(s2).append("\n").append(s)
					.append("\t").append("¥").append(d).append("\t\t")
					.append(k).append("\t\t").append("¥")
					.append(d * (double) k).append("\t").toString();
			System.out.print("\t是否继续(y/n)");
			s1 = scanner.next();
		} while (s1.equals("y"));
		d2 = d1 * d4;
		System.out.println("\n");
		System.out.println("*****************消费清单*********************");
		System.out.println("物品\t\t单价\t\t个数\t\t金额\t");
		System.out.print(s2);
		System.out.println((new StringBuilder()).append("\n折扣:\t").append(d4)
				.toString());
		System.out.println((new StringBuilder()).append("金额总计:\t¥").append(d2)
				.toString());
		System.out.print("实际交费:\t¥");
		double d3 = scanner.nextDouble();
		System.out.println((new StringBuilder()).append("找钱:\t¥").append(
				d3 - d2).toString());
		int i1 = ((int) d2 / 100) * 3;
		int j1 = 0;
		do {
			if (j1 >= custNo.length)
				break;
			if (custNo[j1] == i) {
				custScore[j1] = custScore[j1] + i1;
				System.out.println((new StringBuilder()).append("本次购物所获的积分是: ")
						.append(i1).toString());
				break;
			}
			j1++;
		} while (true);
		System.out.print("\n请'n'返回上一级菜单:");
		if (scanner.next().equals("n")) {
			Menu menu = new Menu();
			menu.setData(goodsName, goodsPrice, custNo, custBirth, custScore);
			menu.showMainMenu();
		}
	}

	public String goodsName[];
	public double goodsPrice[];
	public int custNo[];
	public String custBirth[];
	public int custScore[];
}

//系统开启类

package cn.itcast;

import java.util.Scanner;

/**
 * 系统开启类
 * 
 * @author Administrator
 * 
 */
public class StartSMS {

	public StartSMS() {
	}

	public static void main(String args[]) {
		Data data = new Data();
		data.ini();
		Menu menu = new Menu();
		menu.setData(data.goodsName, data.goodsPrice, data.custNo,
				data.custBirth, data.custScore);
		menu.showLoginMenu();
		boolean flag = true;
		label0: do {
			if (!flag)
				break;
			Scanner scanner = new Scanner(System.in);
			int i = scanner.nextInt();
			VerifyEqual verifyequal = new VerifyEqual();
			switch (i) {
			case 1: // '\001'
				int j = 3;
				do {
					if (j < 1)
						continue label0;
					if (verifyequal.verify(data.manager.username,
							data.manager.password)) {
						menu.showMainMenu();
						continue label0;
					}
					if (j != 1) {
						System.out.println("\n用户名和密码不匹配,请重新输入:");
					} else {
						System.out.println("\n您没有权限进入系统!谢谢!");
						flag = false;
					}
					j--;
				} while (true);

			case 2: // '\002'
				if (verifyequal.verify(data.manager.username,
						data.manager.password)) {
					System.out.print("请输入新的用户名:");
					data.manager.username = scanner.next();
					System.out.print("请输入新的密码:");
					data.manager.password = scanner.next();
					System.out.println("用户名和密码已更改!");
					System.out.println("\n请选择,输入数字:");
				} else {
					System.out.println("抱歉,你没有权限修改!");
					flag = false;
				}
				break;

			case 3: // '\003'
				System.out.println("谢谢您的使用!");
				flag = false;
				break;

			default:
				System.out.print("\n输入有误!请重新选择,输入数字: ");
				break;
			}
		} while (flag);
	}
}




 

//都是一些实现的功能

import java.util.Scanner;

public class CustManagement {

	public CustManagement() {
	}

	public void setData(String as[], double ad[], int ai[], String as1[],
			int ai1[]) {
		goodsName = as;
		goodsPrice = ad;
		custNo = ai;
		custBirth = as1;
		custScore = ai1;
	}

	public void returnLastMenu() {
		System.out.print("\n\n请按'n'返回上一级菜单:");
		Scanner scanner = new Scanner(System.in);
		boolean flag = true;
		do
			if (scanner.next().equals("n")) {
				Menu menu = new Menu();
				menu.setData(goodsName, goodsPrice, custNo, custBirth,
						custScore);
				menu.showCustMMenu();
			} else {
				System.out.print("输入错误, 请重新'n'返回上一级菜单:");
				flag = false;
			}
		while (!flag);
	}

	public void add() {
		System.out.println("购物管理系统 > 客户信息管理 > 添加客户信息\n\n");
		Scanner scanner = new Scanner(System.in);
		System.out.print("请输入会员号(<4位整数>):");
		int i = scanner.nextInt();
		System.out.print("请输入会员生日(月/日<用两位数表示>):");
		String s = scanner.next();
		System.out.print("请输入积分:");
		int j = scanner.nextInt();
		int k = -1;
		int l = 0;
		do {
			if (l >= custNo.length)
				break;
			if (custNo[l] == 0) {
				k = l;
				break;
			}
			l++;
		} while (true);
		custNo[k] = i;
		custBirth[k] = s;
		custScore[k] = j;
		System.out.println("新会员添加成功!");
		returnLastMenu();
	}

	public void modify() {
		System.out.println("购物管理系统 > 客户信息管理 > 修改客户信息\n\n");
		System.out.print("请输入会员号:");
		Scanner scanner = new Scanner(System.in);
		int i = scanner.nextInt();
		System.out.println("  会员号            生日             积分      ");
		System.out.println("------------|------------|---------------");
		int j = -1;
		int k = 0;
		do {
			if (k >= custNo.length)
				break;
			if (custNo[k] == i) {
				System.out.println((new StringBuilder()).append(custNo[k])
						.append("\t\t").append(custBirth[k]).append("\t\t")
						.append(custScore[k]).toString());
				j = k;
				break;
			}
			k++;
		} while (true);
		if (j != -1) {
			System.out
					.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
			System.out.println("\t\t\t\t1.修 改 会 员 生 日.\n");
			System.out.println("\t\t\t\t2.修 改 会 员 积 分.\n");
			System.out
					.println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
			System.out.print("请选择,输入数字:");
			switch (scanner.nextInt()) {
			case 1: // '\001'
				System.out.print("请输入修改后的生日:");
				custBirth[j] = scanner.next();
				System.out.println("生日信息已更改!");
				break;

			case 2: // '\002'
				System.out.print("请输入修改后的会员积分:");
				custScore[j] = scanner.nextInt();
				System.out.println("会员积分已更改!");
				break;
			}
		} else {
			System.out.println("抱歉,没有你查询的会员。");
		}
		returnLastMenu();
	}

	public void search() {
		System.out.println("购物管理系统 > 客户信息管理 > 查询客户信息\n");
		String s = "y";
		Scanner scanner = new Scanner(System.in);
		for (; s.equals("y"); s = scanner.next()) {
			System.out.print("请输入会员号:");
			int i = scanner.nextInt();
			System.out.println("  会员号            生日             积分      ");
			System.out.println("------------|------------|---------------");
			boolean flag = false;
			int j = 0;
			do {
				if (j >= custNo.length)
					break;
				if (custNo[j] == i) {
					System.out.println((new StringBuilder()).append(custNo[j])
							.append("\t\t").append(custBirth[j]).append("\t\t")
							.append(custScore[j]).toString());
					flag = true;
					break;
				}
				j++;
			} while (true);
			if (!flag)
				System.out.println("抱歉,没有你查询的会员信息。");
			System.out.print("\n要继续查询吗(y/n):");
		}

		returnLastMenu();
	}

	public void show() {
		System.out.println("购物管理系统 > 客户信息管理 > 显示客户信息\n\n");
		System.out.println("  会员号            生日             积分      ");
		System.out.println("------------|------------|---------------");
		int i = custNo.length;
		for (int j = 0; j < i && custNo[j] != 0; j++)
			System.out.println((new StringBuilder()).append(custNo[j]).append(
					"\t\t").append(custBirth[j]).append("\t\t").append(
					custScore[j]).toString());

		returnLastMenu();
	}

	public String goodsName[];
	public double goodsPrice[];
	public int custNo[];
	public String custBirth[];
	public int custScore[];
}


 

 

 

 

 

------- <a href="http://edu.csdn.net/heima" target="blank">android培训</a>、<a href="http://edu.csdn.net/heima" target="blank">java培训</a>、期待与您交流! ----------

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值