项目规划书
设计创意:基于当前小商品网购潮流的兴起,为了方便人们的购而制作了该管理系统。该系统的对象主要有用户与管理员,两者必须登录后才能使用。管理员上架商品,用户购买商品并生成订单。
用户:新用户可以注册(且不能注册已经存在的用户),老用户直接登录。
功能:1-更改密码(原密码不能与新密码一致,修改时输入的两次密码不能相同)
2-购买商品 (购买的商品生成价格)
3-查询订单 (输入自己的订单号或手机号即可查询信息)
管理员:管理员为内部账号,只能登录无法注册。
1-查看货架商品 (商品的种类、价格、规格)
2-增加货架物品 (输入商品种类进行删除)
3-删除货架商品 (输入种类并下架)
4-删除购买订单 (输入订单号即可)
5-修改购买订单 (输入订单号,仅能修改收货人姓名,电话,地址)
6-查看全部购买订单
7-查看个人订单 (输入订单号即可)
8-查看用户注册信息
9-删除用户注册信息 (输入用户账号即可)
表现形式:该商店网购管理系统使用IDEA进行编程,通过txt文档进行储存。该程序运用了文件的读取操作,以及Java基本语法,循环,判断,字符串操作,函数方法及其调用。由于该系统运用了文档储存,该系统的数据即可以永久储存。
代码部分展示
package lianxi; import java.io.*; import java.util.Scanner; public class User extends Create { public void register() throws IOException { BufferedReader bufferedReader = new BufferedReader(new FileReader("Shop\\User.txt")); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("Shop\\User.txt", true)); BufferedReader br2 = new BufferedReader(new InputStreamReader(System.in)); System.out.println("----此页面为用户注册页面---"); Scanner scanner = new Scanner(System.in); System.out.println("请设置你的账号"); String name = scanner.next(); System.out.println("请设置你的密码"); String password = br2.readLine(); System.out.println("请设置你的密保"); String problem = br2.readLine(); System.out.println("请设置你的密保答案"); String answer = br2.readLine(); String lineTxt1; while ((lineTxt1 = bufferedReader.readLine()) != null&&!lineTxt1.equals("")) { String[] ss = lineTxt1.split(" "); if (ss[1].equals(name)) { System.out.println("您注册的账号已存在,请重新注册:"); register(); } } String o = "账号: " + name + " ,密码为: " + password + " ,密保问题为: " + problem + " ,密保答案为: " + answer + "\n"; bufferedWriter.write(o); bufferedWriter.close(); System.out.println("恭喜您注册成功,为您转接主菜单"); Homepage homepage = new Homepage(); homepage.homepage(); bufferedReader.close(); br2.close(); } public void login() throws IOException { BufferedReader br = new BufferedReader(new FileReader("Shop\\User.txt")); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); Scanner scanner = new Scanner(System.in); System.out.println("请输入你的账号:"); String name = scanner.next(); System.out.println("请输入你的密码:"); String password = in.readLine(); String name1; while ((name1 = br.readLine()) != null) { String[] ss = name1.split(" "); if (name.equals(ss[1]) && password.equals(ss[3])) { System.out.println("登录成功"); UserCatalogue userCatalogue = new UserCatalogue(); userCatalogue.userCatalogue(); } } System.out.println("登录失败,将返回主页面"); Homepage homepage = new Homepage(); homepage.homepage(); br.close(); } public void changePassword() throws IOException { BufferedReader br = new BufferedReader(new FileReader("Shop\\User.txt")); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); Scanner scanner = new Scanner(System.in); System.out.println("请输入你的原密码"); String password = scanner.next(); String name1; String a = ""; String o = null; while ((name1 = br.readLine()) != null) { if (name1.contains(password)) { String[] ss = name1.split(" "); System.out.println(ss[5]); String answer = ss[7]; Scanner scanner1 = new Scanner(System.in); System.out.println("请输入你的密保答案"); String answer1 = scanner1.next(); if (answer1.equals(answer)) { System.out.println("您的密保答案正确"); System.out.println("请输入你的新密码:"); String newPassword = in.readLine(); System.out.println("请再次输入你的新密码:"); String newPassword1 = in.readLine(); if (!password.equals(newPassword) && newPassword1.equals(newPassword)) { o = "账号: " + ss[1] + " ,密码为: " + newPassword + " ,密保问题为: " + ss[5] + " ,密保答案为: " + ss[7] + "\n"; } else { System.out.println("您输入的两次密码不相同或与原密码相同,修改失败,返回用户主页面"); UserCatalogue userCatalogue = new UserCatalogue(); userCatalogue.userCatalogue(); } } else { System.out.println("您输入的密保答案错误,返回用户主页面"); UserCatalogue userCatalogue = new UserCatalogue(); userCatalogue.userCatalogue(); } } else { a += name1 + "\n"; } } BufferedWriter bufferedWriter1 = new BufferedWriter(new FileWriter("Shop\\User.txt")); bufferedWriter1.close(); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("Shop\\User.txt", true)); bufferedWriter.write(o); bufferedWriter.write(a); System.out.println("修改密码成功!请重新登录"); bufferedWriter.close(); br.close(); User user = new User(); user.login(); } }
package lianxi; import java.io.*; import java.util.Scanner; public class Goods { public void addThing() throws IOException { BufferedReader bufferedReader = new BufferedReader(new FileReader("Shop\\Object.txt")); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("Shop\\Object.txt", true)); Scanner scanner = new Scanner(System.in); System.out.println("请输入你要添加的商品"); String commodity = scanner.next(); System.out.println("请输入你要售卖的价格"); double kg = scanner.nextDouble(); System.out.println("请输入您要上架的单位类型(千克、个、袋、瓶等)"); String l=scanner.next(); String goods; while ((goods = bufferedReader.readLine()) != null) { if (goods.contains(commodity)) { System.out.println("该商品已存在,若想修改价格,请先下架,再上架,为您转接管理员主页面"); CustodianCatalogue custodianCatalogue = new CustodianCatalogue(); custodianCatalogue.custodianCatalogue(); continue; } } bufferedWriter.write(commodity + " " + kg + " 元/"+l); bufferedWriter.newLine(); System.out.println("添加完成!为您转接管理员页面"); bufferedWriter.flush(); bufferedWriter.close(); CustodianCatalogue custodianCatalogue = new CustodianCatalogue(); custodianCatalogue.custodianCatalogue(); } public void deleteThing() throws IOException { BufferedReader bufferedReader = new BufferedReader(new FileReader("Shop\\Object.txt")); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); Scanner scanner = new Scanner(System.in); System.out.println("请输入你要下架的物品"); String commodity = scanner.next(); String object; String a = ""; String a1; String a2 = null; while ((a1 = bufferedReader.readLine()) != null) { a2 += a1; } if (!a2.contains(commodity)) { System.out.println("您输入的下架商品不存在,请重新输入"); deleteThing(); } BufferedReader bufferedReader1 = new BufferedReader(new FileReader("Shop\\Object.txt")); while ((object = bufferedReader1.readLine()) != null) { if (object.contains(commodity)) { continue; } else { BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("Shop\\Object.txt")); bufferedWriter.close(); BufferedWriter bufferedWriter1 = new BufferedWriter(new FileWriter("Shop\\Object.txt", true)); a += object + "\n"; bufferedWriter1.write(a); bufferedWriter1.close(); } } System.out.println("下架成功!为您转接管理员主页"); bufferedReader.close(); CustodianCatalogue custodianCatalogue = new CustodianCatalogue(); custodianCatalogue.custodianCatalogue(); } public void DeleteInformation() throws IOException { BufferedReader bufferedReader = new BufferedReader(new FileReader("Shop\\Order.txt")); Scanner scanner = new Scanner(System.in); System.out.println("请输入你要删除的订单号码"); String number1 = scanner.next(); String lineTxt1; String a2 =""; String a3 =""; while ((lineTxt1 = bufferedReader.readLine()) != null) { if (lineTxt1.contains(number1)) { String[] ss = lineTxt1.split(" "); if (ss[ss.length - 1].equals(number1)) { continue; } else { } } a2 += lineTxt1 + "\n"; } a3+= a2; BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("Shop\\Order.txt")); bufferedWriter.close(); BufferedWriter bufferedWriter1 = new BufferedWriter(new FileWriter("Shop\\Order.txt", true)); bufferedWriter1.write(a3); bufferedWriter1.close(); System.out.println("您操作完毕,转接到管理员页面"); CustodianCatalogue custodianCatalogue = new CustodianCatalogue(); custodianCatalogue.custodianCatalogue(); bufferedReader.close(); } }