您好,登錄后才能下訂單哦!
這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)碛嘘P(guān)java中怎么實(shí)現(xiàn)一個(gè)航空用戶管理系統(tǒng),文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
1. 用戶添加
2. 密碼修改
3. 個(gè)人信息查看
4. 賬號(hào)狀態(tài)修改(禁用0、啟用1)
5. 用戶登錄(被禁用賬號(hào)無法登錄并提示友好的消息)
6. 修改用戶角色(設(shè)置取消管理員)
7. 用戶列表
8. 查詢指定辦事處的員工
9. 刪除用戶
1. 辦事處添加
2. 辦事處列表
注意:管理員具備以上所有功能,普通用戶只有密碼修改和個(gè)人信息查看功能
用戶類(User):
id,賬號(hào)(username),密碼(passord),年齡(age),角色(role),郵箱(email),辦事處id(officeID),賬戶狀態(tài)(status)
辦事處類(Office):
id,辦公室名(officeName)
要求使用技術(shù)參數(shù)如下:
1.分支與循環(huán)
2.數(shù)組或ArrayList
3.方法
4.構(gòu)造器
5.setter/getter
6.抽象類或接口
7.多態(tài)
8.Scanner類
1.題目中管理員與用戶的功能實(shí)現(xiàn)不同,普通用戶只有登錄系統(tǒng)、密碼修改與個(gè)人信息查看功能,而管理員實(shí)現(xiàn)的功能更多,包含了普通用戶的所有功能,那么我可以在登錄時(shí)就進(jìn)行分辨,不同用戶所獲得的功能菜單界面不同。
2.管理員可以設(shè)置狀態(tài),如果狀態(tài)為禁用則無法登錄。(實(shí)現(xiàn)方法可以放在用戶登錄中)
3.默認(rèn)管理員admin/admin123(可以設(shè)置一個(gè)初始化塊,初始化塊又稱游離塊,是一個(gè)沒有名稱的代碼塊,執(zhí)行時(shí)間一般在創(chuàng)建對(duì)象執(zhí)行構(gòu)造器前先執(zhí)行,并且執(zhí)行次數(shù)取決于對(duì)象的創(chuàng)建次數(shù),作用于將多個(gè)構(gòu)造器中的重復(fù)代碼提取到一起統(tǒng)一執(zhí)行. )
4.個(gè)人信息查看只能查看個(gè)人的信息,沒法看到其他用戶的信息。(設(shè)置一個(gè)靜態(tài)變量,登陸時(shí)的用戶名存儲(chǔ)在里面,個(gè)人信息查看通過該靜態(tài)變量在信息存儲(chǔ)中查找)
5.接口(這次的接口沒有寫好,可以將UserMange中的方法都放進(jìn)接口中,在UserMange類中實(shí)現(xiàn),OfficeMange類中也一樣)
內(nèi)容實(shí)現(xiàn):
User類:
package com.softeem.j2106.work; /** * @author admin * 2021/7/17 */ public class User { private int id; private String username; private String password; private int age; private boolean role; private String email; private int officeID; private boolean status; public User() { } public User(int id, String username, String password, int age, boolean role, String email, int officeID, boolean status) { this.id = id; this.username = username; this.password = password; this.age = age; this.role = role; this.email = email; this.officeID = officeID; this.status = status; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public int getOfficeID() { return officeID; } public void setOfficeID(int officeID) { this.officeID = officeID; } public boolean isRole() { return role; } public void setRole(boolean role) { this.role = role; } public boolean isStatus() { return status; } public void setStatus(boolean status) { this.status = status; } @Override public String toString() { return "User{" + "id=" + id + ", username='" + username + '\'' + ", password='" + password + '\'' + ", age=" + age + ", role=" + role + ", email='" + email + '\'' + ", officeID=" + officeID + ", status=" + status + '}'; } }
office類:
package com.softeem.j2106.work; /** * @author admin * 2021/7/17 */ public class Office { private int officeID; private String officeName; public Office() { } public Office(int officeID, String officeName) { this.officeID = officeID; this.officeName = officeName; } public int getOfficeID() { return officeID; } public void setOfficeID(int officeID) { this.officeID = officeID; } public String getOfficeName() { return officeName; } public void setOfficeName(String officeName) { this.officeName = officeName; } @Override public String toString() { return "Office{" + "officeID=" + officeID + ", officeName='" + officeName + '\'' + '}'; } }
Inter接口:
package com.softeem.j2106.work; public interface Inter { public void ShowAll(); }
usermange:
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; } /** * 個(gè)人信息查看 */ 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; } /** * 賬號(hào)狀態(tài)修改 */ 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)) { //將當(dāng)前元素置為空 // stus[i] = null; //后續(xù)的元素前移 覆蓋空白位置(避免碎片化) System.arraycopy(users, i + 1, users, i, users.length - index - 1); index--; return true; } } return false; } /** * 用戶列表 */ @Override public 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; } /**辦事處列表*/ @Override public void ShowAll() { for (Office office : off) { if (office != null) { System.out.println(office); } } } }
tset類:(實(shí)現(xiàn))
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("請(qǐng)輸入賬號(hào):"); String username = sc.next(); loginname = username; msg("請(qǐng)輸入密碼:"); 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("賬號(hào)被禁用!"); start(); } } public static void sign1() { msg("=========SOFTEEM管理員管理系統(tǒng)========="); msg("[1] 用戶添加"); msg("[2] 密碼修改"); msg("[3] 個(gè)人信息查看"); msg("[4] 賬號(hào)狀態(tài)修改"); msg("[5] 修改用戶角色"); msg("[6] 用戶列表"); msg("[7] 查詢指定辦事處的員工"); msg("[8] 刪除員工"); msg("[9] 用戶登錄"); msg("[10] 辦事處添加"); msg("[11] 辦事處列表"); msg("[0] 退出系統(tǒng)"); 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("謝謝使用,再見!"); //系統(tǒng)退出(關(guān)閉JVM) System.exit(0); break; default: msg("指令錯(cuò)誤,請(qǐng)重新輸入"); sign1(); break; } } public static void sign2() { msg("==========SOFTEEM用戶管理系統(tǒng)=========="); msg("[1] 個(gè)人查看"); msg("[2] 密碼修改"); msg("[0] 退出系統(tǒng)"); 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("謝謝使用,再見!"); //系統(tǒng)退出(關(guān)閉JVM) System.exit(0); break; default: msg("指令錯(cuò)誤,請(qǐng)重新輸入"); 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("請(qǐng)輸入新密碼:"); String password = sc.next(); if (a.updatePassword(password)) { msg("修改成功"); } else { msg("修改失敗"); } } private static void addUser() { msg("請(qǐng)輸入ID:"); int id = sc.nextInt(); msg("請(qǐng)輸入用戶名:"); String name = sc.next(); msg("請(qǐng)輸入密碼:"); String password = sc.next(); msg("請(qǐng)輸入年齡:"); int age = sc.nextInt(); msg("設(shè)置為管理員【1】是: 【0】否"); int i = sc.nextInt(); boolean role = true; if (i == 1){ role = true; }else if (i == 0){ role = false; }else { msg("請(qǐng)輸入正確的指令"); } msg("請(qǐng)輸入郵箱:"); String emial = sc.next(); msg("請(qǐng)輸入辦事處ID:"); int officeid = sc.nextInt(); msg("設(shè)置狀態(tài)【1】啟用: 【0】禁用"); int j = sc.nextInt(); boolean status = true; if (j == 1){ status = true; }else if (j == 0){ status = false; }else { msg("請(qǐng)輸入正確的指令"); } 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("請(qǐng)輸入officeID:"); int id = sc.nextInt(); msg("請(qǐng)輸入辦事處名:"); String name = sc.next(); Office o = new Office(id,name); if (b.officeAdd(o)){ msg("添加成功!!"); } else { msg("容量不足!!"); } sign1(); } public static void updateStatus() { msg("請(qǐng)輸入修改用戶名:"); String username = sc.next(); msg("請(qǐng)修改用戶的賬戶狀態(tài)(禁用0/啟用1):"); int j = sc.nextInt(); boolean status = true; if (j == 1){ status = true; }else if (j == 0){ status = false; }else { msg("請(qǐng)輸入正確的指令"); } if (a.changeStatus(username, status)) { msg("修改成功"); } else { msg("修改失敗"); } sign1(); } /**修改用戶的角色信息*/ public static void updateRole() { msg("請(qǐng)輸入修改用戶名:"); String username = sc.next(); msg("請(qǐng)修改用戶的角色信息(禁用0/啟用1):"); int i = sc.nextInt(); boolean role = true; if (i == 1){ role = true; }else if (i == 0){ role = false; }else { msg("請(qǐng)輸入正確的指令"); } if (a.changeAdmin(username, role)) { msg("修改成功"); } else { msg("修改失敗"); } sign1(); } /**用戶刪除*/ public static void delUser() { msg("請(qǐng)輸入ID:"); int Id = sc.nextInt(); if (a.delete(Id)) { msg("刪除成功!!"); } else { msg("用戶不存在!!"); } //返回上一級(jí) sign1(); } /**用戶列表*/ public static void listUser() { a.ShowAll(); //返回上一級(jí) sign1(); } /**辦事處列表*/ public static void listOffice(){ b.ShowAll(); sign1(); } private static void Search() { msg("請(qǐng)輸入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(); } }
用戶登錄:
管理員登錄:
用戶登錄:
上述就是小編為大家分享的java中怎么實(shí)現(xiàn)一個(gè)航空用戶管理系統(tǒng)了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。