菜鸟问为什么实现不了?可以实现多个用户注册
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
public class Client {
public static void main(String[] args) throws Exception {
launch();
}
public static void launch() throws Exception {
boolean exit = false;
Map<String,User> reg = new HashMap<String,User>();
while(!exit) {
System.out.println("****欢迎进入奖客富翁系统*****");
System.out.println(" 1.注册");
System.out.println(" 2.登陆");
System.out.println(" 3.抽奖");
System.out.println("****************************");
System.out.print("请选择菜单:");
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
String option = read.readLine();
option = option.replaceAll("
[解决办法]
\t", "");
System.out.println();
if("1".equals(option)
[解决办法]
"2".equals(option)
[解决办法]
"3".equals(option)) {
if("1".equals(option)) {
register(reg);
} else if("2".equals(option)) {
login(reg);
} else {
lottery();
}
}
System.out.print("继续吗?(y/n):");
read = new BufferedReader(new InputStreamReader(System.in));
option = read.readLine();
option = option.replaceAll("
[解决办法]
\t", "");
if("y".equals(option)) {
System.out.println();
System.out.println();
} else {
System.out.println("系统推出,谢谢使用!");
exit = true;
}
}
}
private static void register(Map<String,User> reg) throws Exception {
String username = "";
String password = "";
String cardno = "";
System.out.println("[奖客富翁系统 > 注册]");
System.out.println("请填写个人注册信息");
System.out.print("用户名:");
BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
username = strin.readLine();
username = username.replaceAll("
------解决方案--------------------
\t", "");
System.out.print("密 码:");
strin = new BufferedReader(new InputStreamReader(System.in));
password = strin.readLine();
password = password.replaceAll("
[解决办法]
\t", "");
cardno = String.valueOf(Math.round(1000 + Math.random() * 8999));
System.out.println("注册成功,请记好您的会员卡号");
System.out.format("%-6s\t%-10s"+"会员卡号","用户名","密码");
System.out.println();
System.out.format("%-6s\t%-10s"+cardno,username,password);
System.out.println();
User user = new User();
user.setUsername(username);
user.setPassword(password);
user.setCardno(cardno);
reg.put(username, user);
}
private static void login(Map<String,User> reg) throws Exception {
String username = "";
String password = "";
System.out.println("[奖客富翁系统 > 登录]");
System.out.print("请输入用户名:");
BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
username = strin.readLine();
username = username.replaceAll("
[解决办法]
\t", "");
System.out.print("请输入密 码:");
strin = new BufferedReader(new InputStreamReader(System.in));
password = strin.readLine();
password = password.replaceAll("
[解决办法]
\t", "");
User user = reg.get(username);
if(user == null) {
System.out.println("您输入的用户名还没注册!");
return;
} else {
if(!password.equals(user.getPassword())) {
System.out.println("您输入的密码有误!");
return;
} else {
System.out.println("欢迎您," + username);
}
}
}
private static void lottery() {
}
}