运行页面
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class RestaurantManager {
public static void main(String[] args) throws IOException {
Pay p=new Pay();
System.out.println("------------------------------------");
System.out.println("\t 李氏餐厅欢迎您 ");
System.out.println("------------------------------------");
System.out.println("您是否要点菜 如果点菜请按:1 取消请按:2");
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
for(;;) {
String namber=bufferedReader.readLine();
if (namber.equals("1")) {
Montey t=new Montey();
t.mt();
p.pay();
System.out.println("欢迎下次光临,祝您生活愉快");
BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("E:\\java\\Project\\src\\First\\Menu"));
bufferedReader.close();
return;
}else if (namber.equals("2")) {
System.out.println("欢迎下次光临");
return;
}else{
System.out.println("对不起您输入的号码有错请重新输入");
}
}
}
}
菜单页面
import java.awt.List;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;
import org.omg.CORBA.PUBLIC_MEMBER;
class Menu {
public int montey=0;
public void name() throws IOException {
System.out.println("我们的特色有以下几种:");
HashMap<String, String>hM=new HashMap<String,String>();
hM.put("1","红烧肉");
hM.put("2","火锅");
hM.put("3","麻辣烫");
hM.put("4","饺子");
hM.put("5","牛肉面");
hM.put("6","石锅菜");
hM.put("7","啤酒");
Set key=hM.keySet();
Iterator it=key.iterator();
while (it.hasNext()) {
String st = (String) it.next();
String name=(String)hM.get(st);
System.out.println(st+"\t"+name);
}
System.out.println("价钱分别是:");
HashMap<String,Integer>mp=new HashMap<String,Integer>();
mp.put("红烧肉",80);
mp.put("火锅",65);
mp.put("麻辣烫",26);
mp.put("饺子",18);
mp.put("牛肉面",20);
mp.put("石锅菜",39);
mp.put("啤酒",10);
Set keys=mp.keySet();
Iterator in=keys.iterator();
while (in.hasNext()) {
String str = (String) in.next();
int montey=(int)mp.get(str);
System.out.println(str+"\t"+montey+"元");
}
System.out.println("请选择您要吃的东西的序号:");
BufferedReader bufferedReader =new BufferedReader(new InputStreamReader(System.in));
for (;;) {
String i=bufferedReader.readLine();
if (i.equals("1")||i.equals("2")||i.equals("3")||i.equals("4")||i.equals("5")||i.equals("6")||i.equals("7")) {
System.out.println(mp.get(hM.get(i))+"元");
montey=mp.get(hM.get(i));
BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("E:\\java\\Project\\src\\First\\Menu",true));
bufferedWriter.write(hM.get(i)+" "+mp.get(hM.get(i))+"元"+" ");
bufferedWriter.close();
return;
}else {
System.out.println("您输入的号码错误请重新输入");
}
}
}
public int mon() {
return montey;
}
}
观看菜单
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
class Montey {
static int i;
static Boolean boolean1=true;
public void mt() throws IOException {
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
BufferedReader bufferedReader2=new BufferedReader(new FileReader("E:\\\\java\\\\Project\\\\src\\\\First\\\\Menu"));
Menu m=new Menu();
m.name();
i=m.mon();
for(;;) {
System.out.println("是否继续点菜 如果继续请按:y 停止请按:n");
String x=bufferedReader.readLine();
if (x.equals("y")) {
m.name();
i=m.mon()+i;
}else if (x.equals("n")) {
for(;;) {
System.out.println("点餐完成是否查看菜单并确定付款 1.查看 2.付款 ");
String z=bufferedReader.readLine();
if (z.equals("1")) {
System.out.print("您的菜单为:");
char[] arr=new char[1000];
int num=bufferedReader2.read(arr);
String str=new String(arr);
System.out.println(str);
System.out.println("确定付款吗???\n 1.确定 2.取消");
for(;;) {
String t=bufferedReader.readLine();
if (t.equals("1")) {
System.out.println("您消费的金额为:"+i+" 元");
return;
}else if(t.equals("2")) {
System.out.println("订单已取消");
boolean1=false;
return;
}else {
System.out.println("您输入的数字有误请重新输入");
}
}
}else if (z.equals("2")) {
System.out.println("您消费的金额为:"+i+" 元");
return;
}else {
System.out.println("您的输入有误请重新输入");
}
}
}
}
}
public int xiao() {
return i;
}
public boolean jie() {
return boolean1;
}
}
支付
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
class Pay {
public void pay() throws IOException {
Bank b=new Bank();
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
Montey monty=new Montey();
if(monty.jie()) {
for (;;) {
System.out.println("请选择支付方式 1.银行卡支付 2.现金支付");
for(;;) {
String a=bufferedReader.readLine();
if (a.equals("1")) {
System.out.print("请输入密码:");
b.code();
return;
}else if (a.equals("2")) {
System.out.println("请支付现金");
System.out.println("欢迎下次光临,祝您生活愉快");
return;
}else {
System.out.println("您输入的号码不正确请重新输入");
}
}
}
}else {
return;
}
}
}
银行
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.FormatFlagsConversionMismatchException;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
class Change {
static String Newname;
static String newpassword;
static String newpassword2;
public void change() throws IOException {
int num=0;
System.out.println("——————————————欢迎来到更改密码页面——————————————");
BufferedReader bufferedReader=new BufferedReader(new FileReader("E:\\\\java\\\\Project\\\\src\\\\First\\\\user.txt"));
List<Information> userlist = new ArrayList<Information>();
String st;
while((st = bufferedReader.readLine())!=null){
String []arr=st.split(",");
String username=arr[0];
String password=arr[1];
Information in=new Information(username,password);
userlist.add(in);
}
bufferedReader.close();
System.out.println("请输入用户名");
BufferedReader bufferedReader2=new BufferedReader(new InputStreamReader(System.in));
Newname=bufferedReader2.readLine();
System.out.println("请输入新的密码");
newpassword =bufferedReader2.readLine();
System.out.println("请再次输入密码");
newpassword2=bufferedReader2.readLine();
boolean z=false;
while(!z) {
if (newpassword.equals(newpassword2)) {
z=true;
}else {
System.out.println("您两次输入的密码不正确请重新输入");
newpassword =bufferedReader2.readLine();
System.out.println("请再次输入密码");
newpassword2=bufferedReader2.readLine();
}
}
for (int i = 0; i < userlist.size(); i++) {
Information in=new Information();
in=userlist.get(i);
if (in.getNewname().equals(Newname)) {
if(!Newname.equals(" "))
in.setNewname(Newname);
if(!newpassword.equals(" "))
in.setNewpassword(newpassword);
}else {
num++;
}
userlist.set(i, in);
}
if (num==userlist.size()-1) {
}else {
System.out.println("您输入的账号不存在请重新输入");
change();
return;
}
BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("E:\\\\java\\\\Project\\\\src\\\\First\\\\user.txt"));
for(Information x : userlist) {
bufferedWriter.write(x.toString());
bufferedWriter.newLine();
bufferedWriter.flush();
}
if (bufferedWriter !=null) {
bufferedWriter.close();
}
System.out.println("修改成功!!!");
// Recharge r=new Recharge();
// r.choice();
// System.out.println("恭喜您充值成功!!!");
// System.out.println();
// System.out.print("请您输入密码继续完成支付谢谢:");
// Bank bank=new Bank();
// bank.code();
}
}
充值
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
class Enterio {
public boolean reader(String username, String password) throws IOException {
File file = new File("E:\\java\\Project\\src\\First\\user.txt");
boolean flag = false;
BufferedReader br = new BufferedReader(new FileReader(file));
String line = null;
while ((line = br.readLine()) != null) {
String[] arr = line.split(",");
if (arr[0].equals(username) && arr[1].equals(password)) {
flag = true;
break;
}
}
br.close();
return flag;
}
}
class Recharge {
static boolean flag;
static int c;
static boolean x=true;
Scanner sc = new Scanner(System.in);
public void choice() throws IOException {
Bank bank=new Bank();
Login zhu=new Login();
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
Scanner input=new Scanner(System.in);
for(int i=3;i>0;i--) {
System.out.println("是否选择充值 1.充值 2.不充值");
String cho=bufferedReader.readLine();
switch (cho) {
case "1":
Enterio enterio = new Enterio();
System.out.println("请输入用户名:");
String username = sc.nextLine();
System.out.println("请输入密码:");
String str1 = sc.nextLine();
flag = false;
try {
flag = enterio.reader(username, str1);
} catch (IOException e) {
e.printStackTrace();
}
if (flag) {
System.out.println("您输入的密码正确请输入充值金额");
c=input.nextInt();
c=c+bank.mon();
return;
} else if (i==1) {
System.out.println("对不起您的银行账号已被锁定");
System.out.println("是否重新注册账号:1.注册 2.修改密码 3.不注册");
for(;;) {
String z=bufferedReader.readLine();
if (z.equals("1")) {
try {
zhu.chuan();
} catch (IOException e) {
e.printStackTrace();
}
choice();
return;
}else if(z.equals("2")) {
Change b=new Change();
b.change();
choice();
return;
}else if (z.equals("3")) {
x=false;
return;
}else {
System.out.println("您输入的号码有误请重新输入");
}
}
}
else {
System.out.println("你输入的号码有误请重新输入");
System.out.println("您还有"+(i-1)+"次机会");
}
break;
case "2":
System.out.println("对不起您的点餐失败");
x=false;
return;
default:
System.out.println("您输入的数字有误请重新输入");
i++;
}
}
}
public int mont() {
return c;
}
public boolean panduan() {
return x;
}
}
注册页面
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
class Login {
String newpassword;
String nextpassword;
String name;
Information in=new Information();
public void lo() throws IOException {
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
System.out.println("————————————欢迎来到注册页面————————————");
System.out.println("请输入用户名:");
name=bufferedReader.readLine();
BufferedReader bufferedReader1=new BufferedReader(new FileReader("E:\\\\java\\\\Project\\\\src\\\\First\\\\user.txt"));
List<Information> userlist = new ArrayList<Information>();
String st;
while((st = bufferedReader1.readLine())!=null){
String []arr=st.split(",");
String username=arr[0];
String password=arr[1];
Information in=new Information(username,password);
userlist.add(in);
}
bufferedReader1.close();
for (int i = 0; i < userlist.size(); i++) {
Information in=new Information();
in=userlist.get(i);
if (in.getNewname().equals(name)) {
System.out.println("您输入的账号已存在请选择是否重新注册或修改密码");
for(;;) {
System.out.println("1.重新注册 2.修改密码 ");
String xuan=bufferedReader.readLine();
if (xuan.equals("1")) {
lo();
return;
}else if(xuan.equals("2")) {
Change gai=new Change();
gai.change();
return;
}else {
System.out.println("您输入的号码有误请重新输入");
}
}
}
}
for(;;) {
System.out.println("请输入密码:");
newpassword=bufferedReader.readLine();
System.out.println("请再一次输入密码:");
nextpassword=bufferedReader.readLine();
in.setNewpassword(newpassword);
in.setNewname(name);
if (newpassword.equals(nextpassword)) {
System.out.println("恭喜您注册成功!!!");
return;
}else {
System.out.println("您两次输入的密码不相同请重新输入");
}
}
}
public void chuan() throws IOException {
this.lo();
BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("E:\\\\java\\\\Project\\\\src\\\\First\\\\user.txt",true));
bufferedWriter.write(in.getNewname()+","+in.getNewpassword()+",");
bufferedWriter.newLine();
bufferedWriter.close();
}
}
修改密码页面
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.FormatFlagsConversionMismatchException;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
class Change {
static String Newname;
static String newpassword;
static String newpassword2;
public void change() throws IOException {
int num=0;
System.out.println("——————————————欢迎来到更改密码页面——————————————");
BufferedReader bufferedReader=new BufferedReader(new FileReader("E:\\\\java\\\\Project\\\\src\\\\First\\\\user.txt"));
List<Information> userlist = new ArrayList<Information>();
String st;
while((st = bufferedReader.readLine())!=null){
String []arr=st.split(",");
String username=arr[0];
String password=arr[1];
Information in=new Information(username,password);
userlist.add(in);
}
bufferedReader.close();
System.out.println("请输入用户名");
BufferedReader bufferedReader2=new BufferedReader(new InputStreamReader(System.in));
Newname=bufferedReader2.readLine();
System.out.println("请输入新的密码");
newpassword =bufferedReader2.readLine();
System.out.println("请再次输入密码");
newpassword2=bufferedReader2.readLine();
boolean z=false;
while(!z) {
if (newpassword.equals(newpassword2)) {
z=true;
}else {
System.out.println("您两次输入的密码不正确请重新输入");
newpassword =bufferedReader2.readLine();
System.out.println("请再次输入密码");
newpassword2=bufferedReader2.readLine();
}
}
for (int i = 0; i < userlist.size(); i++) {
Information in=new Information();
in=userlist.get(i);
if (in.getNewname().equals(Newname)) {
if(!Newname.equals(" "))
in.setNewname(Newname);
if(!newpassword.equals(" "))
in.setNewpassword(newpassword);
}else {
num++;
}
userlist.set(i, in);
}
if (num==userlist.size()-1) {
}else {
System.out.println("您输入的账号不存在请重新输入");
change();
return;
}
BufferedWriter bufferedWriter=new BufferedWriter(new FileWriter("E:\\\\java\\\\Project\\\\src\\\\First\\\\user.txt"));
for(Information x : userlist) {
bufferedWriter.write(x.toString());
bufferedWriter.newLine();
bufferedWriter.flush();
}
if (bufferedWriter !=null) {
bufferedWriter.close();
}
System.out.println("修改成功!!!");
}
}
用户信息
class Information {
private String newname;
private String newpassword;
public Information() {
}
public Information(String newname, String newpassword) {
this.newname = newname;
this.newpassword = newpassword;
}
public String getNewname() {
return newname;
}
public void setNewname(String newname) {
this.newname = newname;
}
public String getNewpassword() {
return newpassword;
}
public void setNewpassword(String newpassword) {
this.newpassword = newpassword;
}
@Override
public String toString() {
return newname+ ","+newpassword+",";
}
}
结束