点餐及支付系统

简介: 点餐及支付系统

文章目录

代码展示

运行页面

菜单页面

观看菜单

支付

银行

充值

注册页面

修改密码页面

用户信息

结束


代码展示


运行页面


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+",";
  }
}

结束


谢谢观看

相关文章
|
XML 移动开发 API
微信支付开发(7) H5支付
关键字:微信支付 微信支付v3 H5支付 wap支付 prepay_id 作者:方倍工作室原文: http://www.cnblogs.com/txw1958/p/wxpayv3_h5.html    本文介绍微信支付下的H5支付实现流程。
3419 1
|
Java 数据安全/隐私保护
支付宝支付功能使用
支付宝支付功能使用
|
算法 网络安全 数据安全/隐私保护
【在线支付】在线支付代码详解
前言: 上一篇文章中(【在线支付】在线支付流程分析)说道,为了保证数据安全,网站把源数据和hmac码发送到第三方,那么,在代码中是如何实现的呢?接收到付款成功的消息,又是如何响应的呢?以向易宝支付为例
226 0
【在线支付】在线支付的方式
【在线支付】在线支付的方式
164 0
|
算法 安全 数据安全/隐私保护
【在线支付】在线支付流程分析
【在线支付】在线支付流程分析
331 0
|
移动开发 安全 API
支付收银台初探(1)
支付收银台初探
464 0
|
小程序 JavaScript
电商收付通系列⑦,合单下单之小程序支付
在我接这个接口的时候,官方并没有明确给出合单支付支持小程序支付,凭借一腔热血去尝试了一下可以成功,prepay_id就是调用JS合单支付获取的。现在再看文档,已经明确列出来了“小程序调起支付”的字眼。所以大家可以放心的接入小程序合单支付哈。支付场景较多,系列文章只介绍小程序合单支付,APP合单支付、JS合单支付依瓢画葫芦,都一样哈。要注意,合单中同一个二级商户只允许有一笔子订单。订单如果需要进行分账等,需要在合单中指定需要进行分账(profit_sharing为true)。
321 0
电商收付通系列⑦,合单下单之小程序支付
J3
快捷餐饮之店家后台订单管理实现
快捷餐饮之店家后台订单管理实现
J3
155 0
快捷餐饮之店家后台订单管理实现
【氚云】线上订单需要付款怎么破?在线支付用起来!
线上订单需要付款怎么破?在线支付用起来!
475 0
【氚云】线上订单需要付款怎么破?在线支付用起来!