一.首先创建Card(package t01)
package t01;
/**
* \* Created with IntelliJ IDEA.
* \* User: DELL
* \* Date: 2022/5/26
* \* Time: 15:02
* \* To change this template use File | Settings | File Templates.
* \* Description:
* \
*/
public class Card {
private String id;
private String name;
private String workUnit;
private String post;
private String telephone;
/**
* 无参构造方法
*/
public Card() {
}
/**
* 有参构造方法
*
* @param id
* @param name
* @param workUnit
* @param post
* @param telephone
*/
public Card(String id, String name, String workUnit, String post, String telephone) {
this.id = id;
this.name = name;
this.workUnit = workUnit;
this.post = post;
this.telephone = telephone;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getWorkUnit() {
return workUnit;
}
public void setWorkUnit(String workUnit) {
this.workUnit = workUnit;
}
public String getPost() {
return post;
}
public void setPost(String post) {
this.post = post;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
@Override
public String toString() {
return "Card{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", workUnit='" + workUnit + '\'' +
", post='" + post + '\'' +
", telephone='" + telephone + '\'' +
'}';
}
}
二.创建public class CardManagement
package t01;
import java.util.Scanner;
/**
* \* Created with IntelliJ IDEA.
* \* User: DELL
* \* Date: 2022/5/26
* \* Time: 15:54
* \* To change this template use File | Settings | File Templates.
* \* Description:
* \
*/
public class CardManagement {
public static void main(String[] args) {
// 声明部分
int mc1;
Scanner sc = new Scanner(System.in);
boolean isRunning = true; // 循环控制变量
while (isRunning) {
// 绘制一级菜单
System.out.println(" 名片管理系统");
System.out.println("================");
System.out.println(" 1. 登录");
System.out.println(" 0. 退出");
System.out.println("================");
System.out.print("输入菜单编号[1,0]:");
mc1 = sc.nextInt();
// 根据用户选择进行相应的操作
switch (mc1) {
case 1:
// 调用登录方法
login();
break;
case 0:
System.out.println("谢谢使用~再见~");
isRunning = false; // 结束循环
break;
default:
System.out.println("输入的菜单编号有误!");
}
}
}
/**
* 登录方法
*/
private static void login() {
String username, password;
Scanner sc = new Scanner(System.in);
System.out.print("用户名:");
username = sc.next();
System.out.print("密 码:");
password = sc.next();
if (username.equals("zlw") && password.equals("030618")) {
System.out.println("登录成功~");
// 调用名片管理方法
cardManagement();
} else {
System.out.println("用户名或密码有误,登录失败~");
}
}
/**
* 名片管理方法
*/
private static void cardManagement() {
int mc2;
Scanner sc = new Scanner(System.in);
boolean isRunning = true; // 循环控制变量
while (isRunning) {
// 绘制二级菜单
System.out.println("=======名片管