A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 陈冬雪 中级黑马   /  2015-8-6 23:04  /  371 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. package cn.itcast_4;

  2. import java.util.Scanner;

  3. import cn.itcast_1.User;
  4. import cn.itcast_2.UserDao;
  5. import cn.itcast_3.UserDaoImpl;

  6. public class UserTest {
  7.         private static final UserDao newUdi = null;

  8.         public static void main(String[] args) {
  9.                 while (true) {
  10.                         System.out.println("欢迎*欢迎*热烈欢迎");
  11.                         System.out.println("1.登录");
  12.                         System.out.println("2.注册");
  13.                         System.out.println("3.退出");
  14.                         System.out.println("请开始吧");
  15.                         Scanner sc = new Scanner(System.in);
  16.                         String line = sc.nextLine();
  17.                         switch (line) {
  18.                         case "1":
  19.                                 System.out.println("你来到登录页面了哦");
  20.                                 System.out.println("请输入你的用户名:");
  21.                                 String username = sc.nextLine();
  22.                                 System.out.println("请输入你的密码:");
  23.                                 String password = sc.nextLine();
  24.                                 /**
  25.                                  * 多态用法 UserDao ud = UserDaoImpl(); 具体类用法
  26.                                  * */
  27.                                 UserDao udi = new UserDaoImpl();
  28.                                 boolean flag = udi.isLogin(username, password);
  29.                                 if (flag) {
  30.                                         System.out.println("你已成功登录,开始你的旅程吧");
  31.                                         System.exit(0);
  32.                                 } else {
  33.                                         System.out.println("登录失败,你不能继续前进了");

  34.                                 }

  35.                                 break;

  36.                         case "2":
  37.                                 System.out.println("欢迎注册,你可以开始新的旅程");
  38.                                 // 键盘录入注册的信息
  39.                                 System.out.println("请输入你的用户名:");
  40.                                 String newUsername = sc.nextLine();
  41.                                 System.out.println("请输入你的密码:");
  42.                                 String newpassword = sc.nextLine();
  43.                                 System.out.println("请输入你的邮箱:");
  44.                                 String newEmail = sc.nextLine();
  45.                                 System.out.println("请输入你的手机号码:");
  46.                                 String newPhone = sc.nextLine();

  47.                                 // 把数据用对象进行封装
  48.                                 User user = new User();
  49.                                 user.setUsername(newUsername);
  50.                                 user.setPassword(newpassword);
  51.                                 user.setEmail(newEmail);
  52.                                 user.setPhone(newPhone);

  53.                                 // 创建用户操作类对象
  54.                                 UserDaoImpl newUdi = new UserDaoImpl();

  55.                                 // 调用注册方法
  56.                                 newUdi.regist(user);
  57.                                 System.out.println("注册成功了");

  58.                                 break;
  59.                         case "3":

  60.                         default:
  61.                                 System.out.println("此次旅程结束了,谢谢使用");
  62.                                 System.exit(0);
  63.                                 break;
  64.                         }

  65.                 }
  66.         }
  67. }
复制代码

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马