java實(shí)現(xiàn)航空用戶管理系統(tǒng)
本文實(shí)例為大家分享了java實(shí)現(xiàn)航空用戶管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
題目內(nèi)容:
某航空公司在其航班到達(dá)的不同的國家的不同地方設(shè)有不同的辦事處,這個(gè)項(xiàng)目要求開發(fā)一個(gè)自動(dòng)化軟件系統(tǒng),該系統(tǒng)將提供給這些辦事處的管理者(role=1)和普通用戶(role=0)用于管理航班信息。根據(jù)以上描述,要求實(shí)現(xiàn)系統(tǒng)的用戶模塊和辦事處模塊,包含以下功能(注:系統(tǒng)存在一個(gè)默認(rèn)管理員admin/admin123):
用戶模塊:
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("請輸入賬號(hào):");
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("賬號(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ò)誤,請重新輸入");
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ò)誤,請重新輸入");
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("設(shè)置為管理員【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("設(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("請輸入正確的指令");
}
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("請修改用戶的賬戶狀態(tài)(禁用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("用戶不存在!!");
}
//返回上一級(jí)
sign1();
}
/**用戶列表*/
public static void listUser() {
a.ShowAll();
//返回上一級(jí)
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();
}
}
用戶登錄:

管理員登錄:

用戶登錄:

寫的不是很好,代碼重復(fù)較多,希望各位朋友可以指點(diǎn)
基本實(shí)現(xiàn)練習(xí)要求,有興趣的朋友可以自行嘗試一下
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Java用單向環(huán)形鏈表來解決約瑟夫環(huán)Josepfu問題
如果把單鏈表的最后一個(gè)節(jié)點(diǎn)的指針指向鏈表頭部,而不是指向NULL,那么就構(gòu)成了一個(gè)單向循環(huán)鏈表,通俗講就是把尾節(jié)點(diǎn)的下一跳指向頭結(jié)點(diǎn)2021-10-10
idea tomcat亂碼問題的解決及相關(guān)設(shè)置的步驟
這篇文章主要介紹了idea tomcat亂碼問題的解決及相關(guān)設(shè)置的步驟,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11
MyBatis Plus Mapper CRUD接口測試方式
在數(shù)據(jù)庫管理系統(tǒng)中,插入記錄是添加新數(shù)據(jù)條目,而刪除操作包括根據(jù)主鍵ID單條刪除和批量刪除,也可以基于特定條件進(jìn)行刪除,刪除操作的SQL語句是通過鍵值對(duì)在Map中拼接而成,如delete from 表 where key1=value1 AND key2=value22024-09-09
Java遞歸基礎(chǔ)與遞歸的宏觀語意實(shí)例分析
這篇文章主要介紹了Java遞歸基礎(chǔ)與遞歸的宏觀語意,結(jié)合實(shí)例形式分析了java遞歸的相關(guān)原理、操作技巧與注意事項(xiàng),需要的朋友可以參考下2020-03-03
java基于servlet實(shí)現(xiàn)文件上傳功能解析
這篇文章主要為大家詳細(xì)介紹了java基于servlet實(shí)現(xiàn)上傳功能,后臺(tái)使用java實(shí)現(xiàn),前端主要是js的ajax實(shí)現(xiàn),感興趣的小伙伴們可以參考一下2016-05-05
Java設(shè)計(jì)模式之java責(zé)任鏈模式詳解
這篇文章主要介紹了JAVA 責(zé)任鏈模式的的相關(guān)資料,文中講解非常細(xì)致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下2021-09-09

