实现注册登录

package com.logein;/*** @author alina* @date 2021年09月15日 10:49 下午* User类,封装用户信息的类*/
public class User {//保存用户名private String username;//保存用户密码private String passwoer;public User() { }public User(String username,String passwoer ){this.username = username;this.passwoer = passwoer;}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPasswoer() {return passwoer;}public void setPasswoer(String passwoer) {this.passwoer = passwoer;}
}
package com.logein;import java.util.Scanner;/*** @author alina* @date 2021年09月15日 10:58 下午* 用户操作的类*/
public class UserInterface {public static void main(String[] args) {Scanner  sc = new Scanner(System.in);UserOperator u = new UserOperator();while (true){//提示用户选择功能System.out.println("Please select the current function:A:register   B:Sign in");String s = sc.nextLine();if (s.equalsIgnoreCase("a")){//选择的是注册功能System.out.println("please input username: ");String username = sc.nextLine();System.out.println("please input password: ");String password = sc.nextLine();u.regegit(username,password);System.out.println("register success!");}else if (s.equalsIgnoreCase("b")){//选择的是登录功能System.out.println("please input username: ");String username = sc.nextLine();System.out.println("please input password: ");String password = sc.nextLine();//判断用户名和密码是不是在集合里面boolean b = u.login(username,password);if (b==false){System.out.println("sign in  default!");}else{System.out.println("sign in  success!");}}else {System.out.println("Please enter the correct option !");break;}}}
}
package com.logein;import java.util.ArrayList;
import java.util.Iterator;/*** @author alina* @date 2021年09月15日 11:11 下午* 操作集合的类* 存储集合,迭代集合*/
public class UserOperator {//成员位置,定义集合,存储User类的对象private ArrayList<User> list = new ArrayList<User>();//定义注册功能,接收用户名和密码,存储到集合//功能不检验用户名是否存在,只要注册就成功public void regegit(String username,String password){list.add(new User(username,password));}//定义登录功能,接收用户名和密码,查询是否在集合中//没查到返回falsepublic boolean login(String username,String password) {Iterator<User> it = list.iterator();while (it.hasNext()){User U = it.next();if(U.getUsername().equals(username) && U.getPasswoer().equals(password)){return true;}}return false;}}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/421766.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

字符串循环同构的最小表示法(转)

循环字符串的最小表示法的问题可以这样描述&#xff1a; 对于一个字符串S&#xff0c;求S的循环的同构字符串S’中字典序最小的一个。 由于语言能力有限&#xff0c;还是用实际例子来解释比较容易&#xff1a;设Sbcad&#xff0c;且S’是S的循环同构的串。S’可以是bcad或者cad…

(JAVA)set

package cn.cast.collection;import java.util.HashSet; import java.util.Iterator; import java.util.Set;/*** author Alina* date 2021年09月16日 11:08 下午* Set 接口派系特点* 不允许存储重复元素* 无序集合&#xff0c;不保证迭代顺序* 没有索引** Set集合迭代方式…

EM Algorithm

(From yesterday to now, I have learning EM for 4 times, and each time I will gain some new ideas and correct some misunderstandings. So cool!) Finally knows that the P(x(i),z(i);θ) means the joint distribution of x and z, parametered by θ. Only if the ta…

(JAVA)hashcode

package cn.cast.collection;/*** author Alina* date 2021年09月19日 8:00 下午* 对象的哈希值* 1.JAVA中&#xff0c;每一个类&#xff0c;都有一个十进制数的哈希值* 2.十进制数&#xff0c;叫做这个对象的哈希值* 3.class Object(){* public native int hashCode();* …

(JAVA)红黑树之自然顺序排序和自定义排序方式

package cn.book.objectarr;/*** author alina* date 2021年08月22日 6:57 下午*/ public class Student implements Comparable<Student> {private String name;private int age;public Student(){}/***** author Alina* date 2021/9/21 9:41 下午* param o* return int…

(JAVA)TreeSet

package homework;/*** author Alina* date 2021年09月22日 10:34 下午*/ class SetTestStudent implements Comparable<SetTestStudent>{private String name;private int gradeScoresOfChinese;private int gradeScoresOfMath;private int gradeScoresOfEnglish;public…

开始

纠结的考试终于结束了。。。可以静下心来整理博客了。。。转载于:https://www.cnblogs.com/Happyhe/archive/2013/05/29/3107121.html

(JAVA)Map集合

package map.demo;import java.util.*;/*** author Alina* date 2021年09月25日 11:20 下午* 底层原理是哈希表&#xff0c;保证唯一性* 允许存储null键&#xff0c;null值* 线程不安全&#xff0c;运行速度快* keyset()可以获取到键* Collections 类的方法reverseOrder :调用空…

各种推荐资料汇总。。。

http://blog.csdn.net/lzt1983/article/details/7914536 转载于:https://www.cnblogs.com/tandychao/archive/2013/05/30/3108022.html

(JAVA)File类

package filedemo;import java.io.File; import java.io.IOException;/*** author Alina* date 2021年10月07日 10:33 下午* File类 提供方法操作 文件 目录 文件夹* 1.两个静态成员变量 static String pathSeparator 路径分隔符* 2.static String separator 名称分隔符* 3.创…

(JAVA)File类2

package filedemo;import java.io.File; import java.io.FileFilter; import java.text.DateFormat; import java.util.Date;/*** author Alina* date 2021年10月10日 11:15 下午* 1.获取文件最后修改时间 Long lastModified()* 2.以数组获取路径下所有文件String[] list();Fi…

MVVM之旅

MVVM的概念已经在脑子里渗透了一段时间&#xff0c;也试着使用了一段时间&#xff0c;就我个人理解&#xff0c;MVVM所倡导的应该是解耦UI跟数据打交道的那一部分&#xff0c;而纯UI的还是写在CodeBehind里。MVVM是以绑定&#xff08;绑定数据、绑定命令&#xff09;来驱动的&a…

变量原理深入讲解

javascript是一种解释执行的语言 语言分解释执行和编译执行 人用直观的编程语言来写程序-------------计算机语言010011100 举例理解&#xff1a; 英文 中国人张三(不会英文) 1、把英文报刊翻译成中文报刊&#xff0c;然后再看(翻译完后&#xff0c;多了一份中…

(JAVA)IO1

IO流四个抽象及类 1.字节输出流&#xff0c;写入任意文件OutputStreamwrite 字节数组 字节数组的一部分 单个字节close 释放资源flush 刷新资源&#xff0c;强制刷新资源 2.字节输入流&#xff0c;读取任意文件InputStreamread 字节数组 字节数组的一部分 单个字节close 关闭资…