展开全部
图片看不清,按你的要求应该是写个控制台程序吧。import java.util.Random;
import java.util.Scanner;
public class Demo {
public static void main(String[] args) {
printHead(); // 打印头信息
boolean flag = false; // 注册标志636f707962616964757a686964616f31333363366164
String username = "";
String password = "";
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("请选择功能:");
int index = scanner.nextInt();
switch (index) {
case 1:
System.out.println("输入用户名:");
username = scanner.next();
System.out.println("输入密码:");
password = scanner.next();
int cardNo = new Random().nextInt(8999) + 1000;
System.out.println("注册成功");
flag = true;
System.out.println("用户名\t密码\t卡号");
System.out.println(username + "\t" + password + "\t" + cardNo);
break;
case 2:
System.out.println("输入用户名:");
String _username = scanner.next();
System.out.println("输入密码:");
String _password = scanner.next();
if (!flag) {
System.out.println("未注册!");
} else {
if (_username.equals(username) && _password.equals(password)) {
System.out.println("登录成功!");
} else {
System.out.println("用户名或密码错误!");
}
}
break;
case 3:
scanner.close();
System.out.println("关闭程序!");
System.exit(1);
break;
default:
break;
}
}
}
public static void printHead() {
System.out.println("********xxx系统*********");
System.out.println("1、注册");
System.out.println("2、登录");
System.out.println("3、退出");
System.out.println("************************");
}
}