面向对象设计作业:商城系统全部代码
资源内容介绍
面向对象设计作业:商城系统全部代码 package shoppingcentre;import shoppingcentre.Cart.Cart;import shoppingcentre.Commodity.Commodity;import shoppingcentre.Shopping.ShoppingDAO;import shoppingcentre.Shopping.ShoppingDAOFileImpl;import shoppingcentre.User.UserAddresses;import shoppingcentre.User.UserDAO;import shoppingcentre.User.UserDAOFileImpl;import shoppingcentre.User.Users;import java.util.ArrayList;import java.util.Scanner;import java.io.File;public class Main { public static void main(String[] args) { UserDAO users = new UserDAOFileImpl(); ShoppingDAO commodity = new ShoppingDAOFileImpl(); ShoppingDAO cart = new ShoppingDAOFileImpl(); commodity.CommodityReadFromFile();//Commodity.txt Users u ; String Account; String Password; int userAddressNumber; System.out.println("---------欢迎使用商城系统---------"); System.out.println("1.登录账号"); System.out.println("2.注册账号"); Scanner scanner = new Scanner(System.in); int choice = scanner.nextInt(); if (choice == 1) { while (true) { System.out.println("请输入账号&密码:"); Account = scanner.next(); Password = scanner.next(); String filePath = "E:\\My item\\IDEA\\shopping centre\\src\\shoppingcentre\\TXT\\Users\\"+Account+".txt"; boolean exists = checkFileExists(filePath); if (exists) { users.UserReadFromFile(Account);//read User.txt u = users.Login(Account, Password); if(u != null){ System.out.println("登陆成功!"); cart.CartReadFromFile(Account);//read Cart.txt break; } }else System.out.println("账号或密码错误"); } } else { while (true) { System.out.println("请输入你要创建的账号&密码"); Account = scanner.next(); Password = scanner.next(); String filePath = "E:\\My item\\IDEA\\shopping centre\\src\\shoppingcentre\\TXT\\Users\\"+Account+".txt"; boolean exists = checkFileExists(filePath); if(exists){//账号已存在 System.out.println("该账号已被注册"); }else{ System.out.println("注册成功"); u = new Users(Account,Password); users.UserManagement(u,choice); break; } } } while(true){ boolean door = false; System.out.println("1.浏览商品"); System.out.println("2.搜索商品"); System.out.println("3.添加商品至购物车"); System.out.println("4.结账"); System.out.println("5.用户设置"); System.out.println("6.退出系统"); Scanner sc = new Scanner(System.in); choice = sc.nextInt(); switch (choice) { case 5: { System.out.println("Your addresses:"); ArrayList<UserAddresses> userAddresses0; userAddresses0=u.getAddressList(); for (UserAddresses userAddress : userAddresses0) { System.out.println(userAddress); } boolean flag1 = true; while (flag1){ System.out.println("1.密码修改"); System.out.println("2.地址添加"); System.out.println("3.地址删除"); System.out.println("4.返回"); Scanner sc51 = new Scanner(System.in); int way = sc51.nextInt(); if (way == 1) { String password1; String password2; while (true) { System.out.println("请输入新密码"); Scanner sc52 = new Scanner(System.in); password1 = sc52.next(); System.out.println("请再一次输入"); Scanner sc53 = new Scanner(System.in); password2 = sc53.next(); if (!password1.equals(password2)) { System.out.println("两次输入不相同!"); } else { System.out.println("修改成功!"); u.setPassword(password1); break; } } }else if (way == 2) { userAddressNumber=users.UserAddressesNumber(u)+1; System.out.print("请输入新地址:"); Scanner sc52 = new Scanner(System.in); String address2 = sc52.next(); UserAddresses userAddresses = new UserAddresses(address2,Integer.toString(userAddressNumber)); u.addAddress(userAddresses); users.UserManagement(u, 1); System.out.println("添加成功"); }else if (way == 3) { System.out.print("删除地址序号:"); Scanner sc53 = new Scanner(System.in); choice = sc53.nextInt(); u=users.UserAddressesDelete(u, choice); }else if (way == 4) { flag1 = false; } } break; } case 6:{ door = true; break; } case 1:{ commodity.DisplayAllCommodity(); break; } case 2:{ String kind ; System.out.println("搜索模式可选:"); System.out.println("1.商品名称"); System.out.println("2.商品种类"); Scanner sc21 = new Scanner(System.in); int category = sc21.nextInt(); if(category == 1){ kind = "name"; }else { kind = "category"; } boolean flag = true; while (flag){ System.out.println("请输入:"); Scanner sc22 = new Scanner(System.in); String search = sc22.next(); if(!commodity.SearchCommodity(search,kind)){ System.out.println("未搜索到商品"); System.out.println("是否继续搜索"); System.out.println("1.继续"); System.out.println("2.退出"); Scanner sc23 = new Scanner(System.in); int choice2 = sc23.nextInt(); if(choice2 == 2){ flag = false; break; } }else { System.out.println("搜索成功"); flag = false; }