java实现航空用户管理系统( 二 )
Inter接口:
package com.softeem.j2106.work; public interface Inter {public void ShowAll();}
usermange:
【java实现航空用户管理系统】package com.softeem.j2106.work; import java.util.Objects; /** * @author admin * 2021/7/17 */public class UserManage implements Inter{private User[] users = new User[10];private int index=1;{users[0] = new User(0,"admin","admin123",20,true,"@163.com",0,true);}/*** 用户登录*/public int sign(String username, String password) {for (int i = 0; i < users.length; i++) {User s = users[i];if ((Objects.nonNull(s))&& s.getUsername().equals(username) && s.getPassword().equals(password)) {if ((s.isRole())&& s.isStatus()) {return 1;} else if ((!s.isRole()) && s.isStatus()) {return 0;} else if (!s.isStatus()){return -2;}}}return -1;}/*** 用户添加*/public boolean add(User u) {if (index >= users.length) {return false;}users[index++] = u;return true;}/*** 密码修改*/public boolean updatePassword(String password) {for (int i = 0; i < users.length; i++) {User user = this.users[i];if ((Objects.nonNull(user))&&user.getPassword() != null) {users[i].setPassword(password);return true;}}return false;}/*** 个人信息查看*/public User SearchByID(String username) {User user = new User();for (User user1 : users) {if ((Objects.nonNull(user))&&user1.getUsername().equals(username)) {user = user1;break;}}return user;}/*** 账号状态修改*/public boolean changeStatus(String username, boolean status) {User user = SearchByID(username);if (user != null) {user.setStatus(status);return true;}return false;}/*** 修改用户角色*/public boolean changeAdmin(String username, boolean role) {User user = SearchByID(username);if (user != null) {user.setRole(role);return true;}return false;}/*** 查询指定办事处的员工*/public boolean searchofficeID(int officeId) {for (User user : users) {if ((Objects.nonNull(user))&&officeId == user.getOfficeID()) {System.out.println(user);return true;}}return false;}/*** 删除用户*/public boolean delete(int id) {for (int i = 0; i < users.length; i++) {User s = users[i];if (Objects.nonNull(s) && Objects.equals(s.getId(), id)) {//将当前元素置为空//stus[i] = null;//后续的元素前移 覆盖空白位置(避免碎片化)System.arraycopy(users, i + 1, users, i, users.length - index - 1);index--;return true;}}return false;}/*** 用户列表*/@Overridepublic void ShowAll() {for (User user : users) {if (user != null) {System.out.println(user);}}}}
officeMange类:
package com.softeem.j2106.work; /** * @author admin * 2021/7/17 */public class OfficeMange implements Inter {private static Office[] off = new Office[10];private int index;/*** 办事处添加*/public boolean officeAdd(Office o) {if (index >= off.length) {return false;}off[index++] = o;return true;}/**办事处列表*/@Overridepublic void ShowAll() {for (Office office : off) {if (office != null) {System.out.println(office);}}}}
tset类:(实现)
package com.softeem.j2106.work; import java.util.Scanner; /** * @author admin * 2021/7/17 */public class Test {static String loginname;static UserManage a = new UserManage();static OfficeMange b = new OfficeMange();static Scanner sc = new Scanner(System.in);public static void start() {msg("==============SOFTEEM用户登录==============");msg("=========================================");msg("请输入账号:");String username = sc.next();loginname = username;msg("请输入密码:");String password = sc.next();if (a.sign(username, password) == 1) {sign1();} else if (a.sign(username, password) == 0) {sign2();} else if (a.sign(username, password) == -1) {msg("登录失败!");start();} else if (a.sign(username, password) == -2) {msg("账号被禁用!");start();}}public static void sign1() {msg("=========SOFTEEM管理员管理系统=========");msg("[1] 用户添加");msg("[2] 密码修改");msg("[3] 个人信息查看");msg("[4] 账号状态修改");msg("[5] 修改用户角色");msg("[6] 用户列表");msg("[7] 查询指定办事处的员工");msg("[8] 删除员工");msg("[9] 用户登录");msg("[10] 办事处添加");msg("[11] 办事处列表");msg("[0] 退出系统");msg("====================================");Scanner sc = new Scanner(System.in);int i = sc.nextInt();switch (i) {case 1:addUser();break;case 2:pwd();sign1();break;case 3:selectbyid();sign1();break;case 4:updateStatus();break;case 5:updateRole();break;case 6:listUser();break;case 7:Search();break;case 8:delUser();break;case 9:start();break;case 10:addOffice();break;case 11:listOffice();break;case 0:msg("谢谢使用 , 再见!");//系统退出(关闭JVM)System.exit(0);break;default:msg("指令错误,请重新输入");sign1();break;}}public static void sign2() {msg("==========SOFTEEM用户管理系统==========");msg("[1] 个人查看");msg("[2] 密码修改");msg("[0] 退出系统");msg("====================================");Scanner sc = new Scanner(System.in);int i = sc.nextInt();switch (i) {case 1:selectbyid();sign2();break;case 2:pwd();sign2();break;case 0:msg("谢谢使用 , 再见!");//系统退出(关闭JVM)System.exit(0);break;default:msg("指令错误,请重新输入");start();break;}}public static void selectbyid() {User u = a.SearchByID(loginname);if (u == null) {msg("您输入的用户id不存在");}System.out.println(u);}public static void pwd() {msg("请输入新密码:");String password = sc.next();if (a.updatePassword(password)) {msg("修改成功");} else {msg("修改失败");}}private static void addUser() {msg("请输入ID:");int id = sc.nextInt();msg("请输入用户名:");String name = sc.next();msg("请输入密码:");String password = sc.next();msg("请输入年龄:");int age = sc.nextInt();msg("设置为管理员【1】是: 【0】否");int i = sc.nextInt();boolean role = true;if (i == 1){role = true;}else if (i == 0){role = false;}else {msg("请输入正确的指令");}msg("请输入邮箱:");String emial = sc.next();msg("请输入办事处ID:");int officeid = sc.nextInt();msg("设置状态【1】启用: 【0】禁用");int j = sc.nextInt();boolean status = true;if (j == 1){status = true;}else if (j == 0){status = false;}else {msg("请输入正确的指令");}User u = new User(id, name, password, age, role, emial, officeid, status);if (a.add(u)) {msg("添加成功!!");} else {msg("容量不足!!");}//返回主菜单sign1();}/**办事处添加*/public static void addOffice(){msg("请输入officeID:");int id = sc.nextInt();msg("请输入办事处名:");String name = sc.next();Office o = new Office(id,name);if (b.officeAdd(o)){msg("添加成功!!");} else {msg("容量不足!!");}sign1();}public static void updateStatus() {msg("请输入修改用户名:");String username = sc.next();msg("请修改用户的账户状态(禁用0/启用1):");int j = sc.nextInt();boolean status = true;if (j == 1){status = true;}else if (j == 0){status = false;}else {msg("请输入正确的指令");}if (a.changeStatus(username, status)) {msg("修改成功");} else {msg("修改失败");}sign1();}/**修改用户的角色信息*/public static void updateRole() {msg("请输入修改用户名:");String username = sc.next();msg("请修改用户的角色信息(禁用0/启用1):");int i = sc.nextInt();boolean role = true;if (i == 1){role = true;}else if (i == 0){role = false;}else {msg("请输入正确的指令");}if (a.changeAdmin(username, role)) {msg("修改成功");} else {msg("修改失败");}sign1();}/**用户删除*/public static void delUser() {msg("请输入ID:");int Id = sc.nextInt();if (a.delete(Id)) {msg("删除成功!!");} else {msg("用户不存在!!");}//返回上一级sign1();}/**用户列表*/public static void listUser() {a.ShowAll();//返回上一级sign1();}/**办事处列表*/public static void listOffice(){b.ShowAll();sign1();}private static void Search() {msg("请输入ID:");int ID = sc.nextInt();if (a.searchofficeID(ID)){}else {msg("未知查询");}sign1();}public static void msg(String msg) {System.out.println(msg);}public static void main(String[] args) {start();}}
推荐阅读
- 航空意外保险必须买吗
- 空客和波音的区别
- 南昌航空大学口碑怎么样 南昌有哪些大学
- 青岛航空是哪个联盟的
- 实现脱贫的根本之策是什么扶贫
- 民用航空分为哪两个部分
- 人的自我实现结果比过程重要
- 人生的理想可以从哪些方面去实现
- 2021随心飞有哪些航空公司
- 祖国统一的意义
