引言
學習接觸java有一段時間了,過了一關又一關,掌握并且應用了許多知識同時也在遺忘,第一次接觸包含各個部分內容的對我來說大型的專案,在寫博客總結的時候回顧為這個專案敲下第一個字符的時候,覺得我能堅持寫完可真棒啊嘿嘿,
需求
該軟體實作以下功能:
1軟體啟動時,首先進入登錄界面進行注冊和登錄功能,
2當登陸成功后,進入選單,首先就可以對開發人員賬戶和密碼進行修改,
3然后可以對開發人員進行增刪改操作
4人員添加成功后,根據選單提示,基于現有的公司成員,組建一個開發團隊以開發一個新的專案,
5組建程序包括將成員插入到團隊中,或從團隊中洗掉某成員,還可以列出團隊中現有成員的串列,開發團隊成員包括架構師、設計師和程式員,
6團隊組建成功,則可以進入專案模塊,添加專案,分配開發團隊進行開發,
思路
系統功能結構如圖所示:

系統流程圖如下:

軟體設計包含如下三個模塊

模塊功能如下:
1team.view 模塊為主控模塊,負責選單的顯示和處理用戶操作
2team.service 模塊為物體物件(Employee及其子類如程式員等)的管理模塊, NameListService和TeamService類分別用各自的陣列來管理公司員工和開發團隊成員物件
3ProjectService是對專案的操作物件類
4domain模塊為Employee及其子類等JavaBean類所在的包
心得:
拆分為用戶登陸注冊,開發人員管理,開發團隊調度管理,開發專案管理這四個功能塊分開進行設計,并進行bug測驗,最后進行匯總除錯,
具體實作
domain包下
雇員類Employee
public class Employee {
private int id;
private String name;
private int age;
private double salary;
public Employee() {
}
public Employee(int id, String name, int age, double salary) {
this.id = id;
this.name = name;
this.age = age;
this.salary = salary;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public String getDetails(){
return id+"\t"+name+"\t"+age+"\t"+salary;
}
@Override
public String toString() {
return getDetails();
}
}
Employee子類:程式員Programmer
public class Programmer extends Employee{
private int memberId;
boolean status=true;
Equipment equipment;
public Programmer(){};
public Programmer(int id, String name, int age, double salary, Equipment equipment) {
// super(id, name, age, salary);
super(id,name,age,salary);
this.equipment=equipment;
}
public int getMemberId() {
return memberId;
}
public void setMemberId(int memberId) {
this.memberId = memberId;
}
public boolean getStatus() {
return status;
}
public void setStatus(boolean status) {
this.status = status;
}
public Equipment getEquipment() {
return equipment;
}
public void setEquipment(Equipment equipment) {
this.equipment = equipment;
}
protected String getMemberdetails(){
return getMemberId()+getDetails();
}
public String getDetailsForTeam(){
return getMemberdetails()+"\t程式員";
}
@Override
public String toString() {
return getDetails()+"\t程式員\t"+status+"\t\t\t\t"+equipment.getDescription();
}
}
Programmer子類:設計師類Desiger:
public class Designer extends Programmer{
double bouns; //獎金
public Designer(){}
public Designer(int id, String name, int age, double salary, Equipment equipment, double bouns) {
super( id, name, age, salary, equipment );
this.bouns = bouns;
}
public double getBouns() {
return bouns;
}
public void setBouns(double bouns) {
this.bouns = bouns;
}
public String getDetailsForTeam(){
return getMemberdetails()+"\t設計師\t"+getBouns();
}
@Override
public String toString() {
return getDetails()+"\t設計師\t"+getStatus()+"\t"+
getBouns()+"\t\t\t"+getEquipment().getDescription();
}
}
Desiger子類:架構師類Architect:
public class Architect extends Designer{
private int stock;//獎勵股票
public Architect(){}
public Architect(int id, String name, int age, double salary, Equipment equipment, double bouns, int stock) {
super( id, name, age, salary, equipment, bouns );
this.stock = stock;
}
public int getStock() {
return stock;
}
public void setStock(int stock) {
this.stock = stock;
}
@Override
public String getDetailsForTeam() {
return getMemberdetails()+"\t架構師\t"+getStatus()+"\t"
+getBouns()+"\t"+getStock()+"\t"+getEquipment().getDescription();
}
@Override
public String toString() {
return getDetails()+"\t架構師\t"+getStatus()+"\t"+
getBouns()+"\t"+getStock()+"\t"+getEquipment().getDescription();
}
}
Equipment介面:
public interface Equipment {
String getDescription();
}
Equipment子類:PC(臺式電腦)
import view.TSUtility;
public class PC implements Equipment{
//model 表示機器的型號
private String model;
//display 表示顯示幕名稱
private String display;
public PC(){
super();
}
public PC(String model, String display) {
this.model = model;
this.display = display;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getDisplay() {
return display;
}
public void setDisplay(String display) {
this.display = display;
}
public PC addPC(){
System.out.println("請輸入需要配置的臺式電腦型號");
String model= TSUtility.readKeyBoard( 10,false );
System.out.println("請輸入需要配置的臺式電腦型號顯示幕名稱");
String display = TSUtility.readKeyBoard( 10,false );
System.out.println("設備添加成功");
return new PC(model,display);
}
@Override
public String getDescription() {
return model + "("+display+")";
}
}
Equipment子類:NoteBook(筆記本電腦)
import view.TSUtility;
public class NoteBook implements Equipment{
private String model;
private double price;
public NoteBook(){
super();
}
public NoteBook(String model, double price) {
this.model = model;
this.price = price;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public NoteBook addNoteBook(){
System.out.println("請輸入需要配置的筆記本電腦的型號:");
String model = TSUtility.readKeyBoard(10, false);
System.out.println("請輸入需要配置的筆記本電腦的價格:");
Double price = TSUtility.readDouble();
System.out.println("設備添加成功!");
return new NoteBook(model, price);
}
@Override
public String getDescription() {
return model + "(" + price + ")";
}
}
Equipment子類:Printer(列印機)
import view.TSUtility;
public class Printer implements Equipment{
private String name;
private String type;
public Printer(){
super();
}
public Printer(String name, String type) {
this.name = name;
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Printer addPrinter(){
System.out.println("請輸入要添加的列印機名稱:");
String name = TSUtility.readKeyBoard( 10 ,false);
System.out.println("請輸入添加的列印機型別:");
String type = TSUtility.readKeyBoard( 10,false );
System.out.println("設備添加成功!");
return new Printer(name,type);
}
@Override
public String getDescription() {
return name+"("+type+")";
}
}
service包下
自定義例外類 TeamException
public class TeamException extends Exception{
public TeamException() {
}
public TeamException(String message) {
super(message);
}
}
開發人員管理模塊:NameListService
import domain.*;
import view.TSUtility;
import java.util.ArrayList;
public class NameListService {
//實作員工的添加(根據職業添加(無,程式員,設計師,架構師))
//c創建一個裝員工的資料集合
private static ArrayList<Employee> employees = new ArrayList<>();
//添加員工id
private int count = 1;
public NameListService() {
super();
}
public NameListService(ArrayList<Employee> employees, int count) {
this.employees = employees;
this.count = count;
}
public ArrayList<Employee> getEmployees() {
return employees;
}
public void setEmployees(ArrayList<Employee> employees) {
this.employees = employees;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
//初始化默認值(用戶資料互通,避免代碼塊資料和自己添加資料無法繼續進行使用的問題)
{
if (employees.isEmpty()) {
employees.add( new Employee( count, "馬云 ", 22, 3000 ) );
employees.add( new Architect( ++count, "馬化騰", 32, 18000, new NoteBook( "聯想T4", 6000 ), 60000, 5000 ) );
employees.add( new Programmer( ++count, "李彥宏", 23, 7000, new PC( "戴爾", "NEC 17寸" ) ) );
employees.add( new Programmer( ++count, "劉強東", 24, 7300, new PC( "戴爾", "三星 17寸" ) ) );
employees.add( new Designer( ++count, "雷軍 ", 50, 10000, new Printer( "激光", "佳能2900" ), 5000 ) );
employees.add( new Programmer( ++count, "任志強", 30, 16800, new PC( "華碩", "三星 17寸" ) ) );
employees.add( new Designer( ++count, "柳傳志", 45, 35500, new PC( "華碩", "三星 17寸" ), 8000 ) );
employees.add( new Architect( ++count, "楊元慶", 35, 6500, new Printer( "針式", "愛普生20k" ), 15500, 1200 ) );
employees.add( new Designer( ++count, "史玉柱", 27, 7800, new NoteBook( "惠普m6", 5800 ), 1500 ) );
employees.add( new Programmer( ++count, "丁磊 ", 26, 6600, new PC( "戴爾", "NEC17寸" ) ) );
employees.add( new Programmer( ++count, "張朝陽 ", 35, 7100, new PC( "華碩", "三星 17寸" ) ) );
employees.add( new Designer( ++count, "楊致遠", 38, 9600, new NoteBook( "惠普m6", 5800 ), 3000 ) );
}
}
//得到所有的員工資料集合
public ArrayList<Employee> getAllEmployees() {
return employees;
}
//得到當前員工
public Employee getEmployee(int id) throws TeamException {
for (int i = 0; i < employees.size(); i++) {
if (employees.get( i ).getId() == id) {
return employees.get( i );
}
}
throw new TeamException( "該員工不存在" );
}
//增加員工
public void addEmployee() throws InterruptedException {
System.out.println( "請輸入需要添加的雇員的職位:" );
System.out.println( "1(無職位)" );
System.out.println( "2(程式員)" );
System.out.println( "3(設計師)" );
System.out.println( "4(架構師)" );
String a = String.valueOf( TSUtility.readMenuSelection() );
if (a.equals( "1" )) {//無職位
System.out.println( "當前雇員職位分配為:無" );
System.out.println( "請輸入當前雇員的姓名:" );
String name = TSUtility.readKeyBoard( 4, false );
System.out.println( "請輸入當前雇員的年齡:" );
int age = TSUtility.readInt();
System.out.println( "請輸入當前雇員的工資:" );
double salary = TSUtility.readDouble();
Employee employee = new Employee( ++count, name, age, salary );
employees.add( employee );
System.out.println( "人員添加成功!" );
TSUtility.readReturn();
} else if (a.equals( "2" )) {//程式員
System.out.println( "當前雇員的職位分配為:程式員" );
System.out.println( "請輸入當前雇員的姓名:" );
String name = TSUtility.readKeyBoard( 4, false );
System.out.println( "請輸入當前雇員的年齡:" );
int age = TSUtility.readInt();
System.out.println( "請輸入當前雇員的工資:" );
double salary = TSUtility.readDouble();
System.out.println( "請為當前雇員配置一臺好的臺式電腦" );
PC pc = new PC().addPC();
Programmer programmer = new Programmer( ++count, name, age, salary, pc );
employees.add( programmer );
TSUtility.readReturn();
} else if (a.equals( "3" )) {//設計師
System.out.println( "當前雇員職位分配為:設計師" );
System.out.println( "請輸入當前雇員的姓名:" );
String name = TSUtility.readKeyBoard( 4, false );
System.out.println( "請輸入當前雇員的年齡:" );
int age = TSUtility.readInt();
System.out.println( "請輸入當前雇員的工資:" );
double salary = TSUtility.readDouble();
System.out.println( "請為當前設計師配置一臺好的筆記本電腦:" );
NoteBook noteBook = new NoteBook().addNoteBook();
System.out.println( "請輸入當前設計師的獎金:" );
double bonus = TSUtility.readDouble();
Designer designer = new Designer( ++count, name, age, salary, noteBook, bonus );
employees.add( designer );
System.out.println( "人員添加成功!" );
TSUtility.readReturn();
} else {//架構師
System.out.println( "當前雇員的職位分配為:架構師" );
System.out.println( "請輸入當前雇員的姓名:" );
String name = TSUtility.readKeyBoard( 4, false );
System.out.println( "請輸入當前雇員的年齡:" );
int age = TSUtility.readInt();
System.out.println( "請輸入當前雇員的工資:" );
double salary = TSUtility.readDouble();
System.out.println( "請為當前架構師配置一臺好的列印設備:" );
Printer printer = new Printer().addPrinter();
System.out.println( "請設定當前架構師的獎金:" );
double bonus = TSUtility.readDouble();
System.out.println( "請設定當前架構師的股票:" );
Integer stock = TSUtility.readstock();
Architect architect = new Architect( ++count, name, age, salary, printer, bonus, stock );
employees.add( architect );
System.out.println( "人員添加成功!" );
TSUtility.readReturn();
}
}
//實作員工的修改(至少修改員工的姓名,年齡,工資)
public void modifyEmployee(int id) throws InterruptedException {
boolean flag = false;
for (int i = 0; i < employees.size(); i++) {
Employee emp = employees.get( i );
if (employees.get( i ).getId() == id) {
System.out.println( "姓名(" + emp.getName() + ")如果不用修改請按Enter鍵" );
String name = TSUtility.readString( 4, emp.getName() );
System.out.println( "年齡(" + emp.getAge() + ")如果不用修改請按Enter鍵" );
int age = Integer.parseInt( TSUtility.readString( 2, emp.getAge() + "" ) );
System.out.println( "工資(" + emp.getSalary() + ")如果不用修改請按Enter鍵" );
Double salary = Double.parseDouble( TSUtility.readString( 10, emp.getSalary() + " " ) );
emp.setName( name );
emp.setAge( age );
emp.setSalary( salary );
employees.set( i, emp );
flag = true;
}
}
if (flag) {
System.out.println( "修改成功!" );
} else {
try {
throw new TeamException( "該員工不存在" );
} catch (TeamException e) {
System.out.println( e.getMessage() );
}
}
}
//實作員工的洗掉(注意員工id需要動態顯示,也就是洗掉后,員工id需要更新)
public void delEmployee(int id) throws TeamException {
boolean flag = false;
for (int i = 0; i < employees.size(); i++) {
if (employees.get( i ).getId() == id) {
employees.remove( i );
for (i = id; i <= employees.size(); i++) {
//個人理解是不停的讓后面的序號-1覆寫前面的從而實作洗掉元素后前后序號排序正常,
employees.get( i - 1 ).setId( employees.get( i - 1 ).getId() - 1 );
}
flag = true;
}
}
if (flag) {
System.out.println( "洗掉成功!" );
count--;
} else {
throw new TeamException( "該員工不存在" );
}
}
//實作員工的查看 (顯示所有資料)
public void showEmployee() throws InterruptedException {
TSUtility.loadSpecialEffects();
System.out.println( "ID\t 姓名\t年齡\t 工資\t 職位\t 狀態\t 獎金\t 股票\t 領用設備" );
for (int i = 0; i < employees.size(); i++) {
System.out.println( " " + employees.get( i ) );
}
}
}
開發人員調度管理模塊:TeamService
import domain.Employee;
import domain.Programmer;
import domain.Employee;
import domain.Printer;
import domain.Architect;
import domain.Designer;
//管理開發團隊成員
public class TeamService {
//自動生成團隊的memberId;
private static int counter = 1;
//團隊人數上限
private final int MAX_MEMBER = 5;
//保留當前團隊成員
private Programmer[] team = new Programmer[MAX_MEMBER];
//團隊實際人數
private int total = 0;
public TeamService() {
}
public TeamService(Programmer[] team, int total, int counter) {
this.team = team;
this.total = total;
this.counter = counter;
}
//回傳team中所有的程式員構成的陣列
public Programmer[] getTeam() {
Programmer[] team = new Programmer[total];
for (int i = 0; i < total; i++) {
team[i] = this.team[i];//賦值
}
return team;
}
//初始化當前團隊成員陣列
public void clearTeam(){
team = new Programmer[MAX_MEMBER];
counter = 1;
total = 0;
this.team = team;
}
//增加團隊成員
public void addMember(Employee e) throws TeamException {
if (total >= MAX_MEMBER) {
throw new TeamException( "成員已滿,不能添加" );
}
if (!(e instanceof Programmer)) {
//instanceof
//instanceof是Java的一個保留關鍵字,左邊是物件,右邊是類,
// 回傳型別是Boolean型別,它的具體作用是測驗左邊的物件是否是右邊類或者該類的子類創建的實體物件,
// 是,則回傳true,否則回傳false,
throw new TeamException( "該成員不是開發人員,無法添加" );
}
Programmer p = (Programmer) e;
if (isExit( p )) {
throw new TeamException( "該員工已在本團隊中" );
}
if (!p.getStatus()) {
throw new TeamException( "該員工已經是某團隊成員" );
}
//限制各類成員人數
int numofArch = 0, numOfDsgn = 0, numOfPrg = 0;
for (int i = 0; i < total; i++) {
if (team[i] instanceof Architect) {
numofArch++;
} else if (team[i] instanceof Designer) {
numOfDsgn++;
} else if (team[i] instanceof Programmer) {
numOfPrg++;
}
}
if (p instanceof Architect) {
if (numofArch > 1) {
throw new TeamException( "團隊中至多只能有一名架構師" );
}
if (numOfDsgn > 2) {
throw new TeamException( "團隊中至多只能有兩名設計師" );
}
if (numOfPrg > 3) {
throw new TeamException( "團隊中至多只能有三名程式員" );
}
}
//添加到陣列
p.setStatus( false );
p.setMemberId( counter++ );
team[total++] = p;
}
//判斷這個成員在團隊中是否存在
private boolean isExit(Programmer p) {
for (int i = 0; i < total; i++) {
if (team[i].getId() == p.getId()) return true;
}
return false;
}
//洗掉指定的團隊成員
public void removeMember(int menmberId) throws TeamException {
int n = 0;
//找到指定員工進行洗掉
for (; n < total; n++) {
if (team[n].getId() == menmberId) {
team[n].setStatus( true );
break;
}
}
//遍歷一遍找不到,報告例外
if (n == total) {
throw new TeamException( "找不到該成員,無法洗掉" );
}
//后面的元素覆寫前面的元素
for (int i = n + 1; i < total; i++) {
team[i - 1] = team[i];
}
team[--total] = null;
//撰寫改變后的id
int i = 1;
for (int j = 0; j < total; j++) {
team[j].setMemberId( i++ );
}
}
}
開發專案管理模塊:ProjectService
import domain.Programmer;
import domain.Project;
import view.TSUtility;
import java.util.ArrayList;
import java.util.Random;
public class ProjectService {
private ArrayList<Project>pro = new ArrayList<>();
private int count = 1;
//添加新專案
public void addProject()throws InterruptedException{
System.out.println("專案參考:--------------------------------------------------");
System.out.println("1.小米官網:開發完成類似于小米官網的web專案.");
System.out.println("2.公益在線商城:貓寧Morning公益商城是中國公益性在線電子商城.");
System.out.println("3.博客系統:Java博客系統,讓每一個有故事的人更好的表達想法!");
System.out.println("4.在線協作檔案編輯系統:一個很常用的功能,適合小組內的檔案編輯,");
System.out.println("------------------------------------------------------------");
TSUtility.readReturn();
System.out.println("請輸入你想添加的專案名: ");
char c = TSUtility.readMenuSelection();
int c1 = 1;
int c2 = 2;
int c3 = 3;
int c4 = 4;
switch (c){
case '1':
Project p1 = new Project();
p1.setProId( count++ );
p1.setProName( "小米官網" );
p1.setDesName( "開發類似小米官網的web專案" );
//如何判斷已經存在一個重名的或者添加的相同的呢?
if (c1==1){
pro.add( p1 );
TSUtility.loadSpecialEffects();
System.out.println("已經添加的專案"+p1.getProName());
c1++;
}else {
System.out.println("專案已經被添加,請添加其他專案");
}
break;
case'2':
Project p2 =new Project();
p2.setProId( count++ );
p2.setProName( "公益在線商城" );
p2.setDesName( "貓寧Morning公益商城是中國公益性在線電子商城." );
if (c2==2){
pro.add( p2 );
TSUtility.loadSpecialEffects();
System.out.println("已經添加的專案"+p2.getProName());
c2++;
}else {
System.out.println("專案已經被添加,請添加其他專案");
}
break;
case'3':
Project p3 = new Project();
p3.setProId( count++ );
p3.setProName( "博客系統" );
p3.setDesName( "Java博客系統,讓每一個有故事的人更好的表達想法!" );
if (c3==1){
pro.add( p3 );
TSUtility.loadSpecialEffects();
System.out.println("已經添加的專案"+p3.getProName());
c3++;
}else {
System.out.println("專案已經被添加,請添加其他專案");
}
break;
case'4':
Project p4 = new Project();
p4.setProId( count++ );
p4.setProName( "在線協作檔案編輯系統" );
p4.setDesName( "一個很常用的功能,適合小組內的檔案編輯," );
if (c4==1){
pro.add( p4 );
TSUtility.loadSpecialEffects();
System.out.println("已經添加的專案"+p4.getProName());
c4++;
}else {
System.out.println("專案已經被添加,請添加其他專案");
}
break;
default:
System.out.println("該專案不存在");
break;
}
}
//專案分配團隊開發
public void dealingPro(Programmer[]team){
//判斷是否存在團隊
if (pro==null){
System.out.println("當前無專案,請先添加專案");
return;
}
//給專案分配團隊
System.out.println("當前團隊人員有:");
for (int i = 0; i < team.length; i++) {
System.out.println(team[i]);
}
System.out.println("請為當前團隊命名:");
String teamName = TSUtility.readKeyBoard( 8,false );
//隨機分配專案
if (team.length!=0){//判斷team是否為空
Random ra = new Random();
int ranNum = ra.nextInt(pro.size());//該方法的作用是在(0,pro.size]之間娶一個隨機值
Project project = this.pro.get( ranNum );
if (project!=null){//判斷project是否為空值
project.setTeamName(teamName);
project.setTeam( team );
project.setStatus( true );
}
}
}
//查看專案當前狀態
public void showPro()throws InterruptedException{
if (pro.size()==0){
TSUtility.loadSpecialEffects();
System.out.println("當前沒有專案,請先添加專案");
}
for (int i = 0; i < pro.size(); i++) {
System.out.println(pro.get( i ).toString());
}
}
//洗掉所選擇的專案
public void delPro(int id )throws TeamException{
boolean flag = false;
for (int i = 0; i < pro.size(); i++) {
if ((pro.get(i).getStatus())!=true) {
if (pro.get(i).getProId() == id) {
pro.remove(i);
for (i = id; i < pro.size(); i++) {
pro.get(i - 1).setProId(pro.get(i - 1).getProId() - 1);//動態ID改變
}
flag = true;
}
} else {
// throw new TeamException("當前專案正在被開發,無法洗掉!");
System.out.println("當前專案正在被開發,無法洗掉!");
System.out.println("如果堅持洗掉請選擇1,退出選擇2");
boolean loopflag = true;
char key = TSUtility.readMenuSelection();
do {
switch (key){
case '1':
for (int j = 0; j < pro.size(); j++) {
if (pro.get( j ).getProId()==id){
pro.remove( j );
for (j = id ;j<pro.size();j++) {
pro.get( j-1 ).setProId( pro.get( j-1 ).getProId()-1 );
}
}
}
System.out.println("洗掉成功");
count--;
loopflag = false;
break;
case '2':
loopflag = false;
break;
default:
System.out.println("輸入有誤");
break;
}
}while (loopflag);
}
}
if (flag) {
System.out.println("洗掉成功!");
count--;
} else {
try {
throw new TeamException("該專案不存在!");
} catch (TeamException e) {
System.out.println( e.getMessage() );
}
}
}
//得到所有專案資料集合
public ArrayList<Project>getALLpro(){
for (int i = 0; i < pro.size(); i++) {
System.out.println(pro.get( i ));
}
return pro;
}
}
view包下
用戶注冊和登錄模塊 Loginview
import java.util.Scanner;
//定義一個LoginView類
//實作注冊方法
//如果沒有賬戶則需要注冊
//如果有賬號則直接進行登錄
//實作登錄功能
//判斷用戶輸入的值是否正確
//如果正確則進入軟體選單
//如果錯誤則重新輸入,限制次數只有5次,超過次數則程式停止,重新啟動
//實作修改用戶密碼功能
//可以實作對用戶名,密碼,或者兩者都可以進行修改即可,
public class Loginview {
//給定屬性,用戶名和密碼,
private String userName = "";
private String passWord;
//注冊功能
public void regist() throws InterruptedException {
TSUtility.loadSpecialEffects();
System.out.println( "開始注冊😊" );
Scanner sc = new Scanner( System.in );
System.out.println( "請輸入賬戶名稱😳(八位以內)" );
String userName = TSUtility.readKeyBoard( 8, false );
this.userName = userName;
System.out.println( "請輸入登錄密碼😳(八位以內)" );
String passWord = TSUtility.readKeyBoard( 8, false );
this.passWord = passWord;
System.out.println( "注冊成功,請登錄!😀" );
}
//登錄功能
public void login() throws InterruptedException {
int count = 5;
boolean flag = true;
//登錄界面的回圈
while (flag) {
System.out.println( "********************🐱" );
System.out.println( "*** <登錄界面> ***" );
System.out.println( "*** (: ***🐱" );
System.out.println( "********************🐱" );
//賬號資訊的輸入與登錄判斷
System.out.println( "請輸入你的賬戶名稱" );
String userName = TSUtility.readKeyBoard( 4, false );
System.out.println( "請輸入你的登錄密碼" );
String password = TSUtility.readKeyBoard( 8, false );
if (this.userName.length() == 0 || this.passWord.length() == 0) {
System.out.println( "未檢測到你的賬號資訊,請重新輸入或注冊" );
regist();
} else if (this.userName.equals( userName ) && this.passWord.equals( password )) {
TSUtility.loadSpecialEffects();
System.out.println( "登錄成功,歡迎你:" + userName );
flag = false;
} else {
count--;
if (count <= 0) {
System.out.println( "登錄次數為零,無法登錄,退出," );
return;
}
System.out.println( "登錄失敗,用戶名不匹配或密碼錯誤,還剩余" + count + "次登錄機會,請重新輸入" );
}
}
}
//修改功能
public void update() throws InterruptedException {
boolean flag = true;
while (flag) {
System.out.println( "************************🐖" );
System.out.println( "*********修改界面*********" );
System.out.println( "***** o(*^@^*)o ***🐱" );
System.out.println( "************************🐖" );
System.out.println( "請輸入您要修改的型別" );
System.out.println( "(1)修改用戶名" );
System.out.println( "(2)修改密碼" );
System.out.println( "(3)修改用戶名和密碼" );
System.out.println( "(4)不做修改" );
Scanner sc = new Scanner( System.in );
String options = sc.next();
if (options.equals( "1" )) {
System.out.println( "請輸入新的賬戶名稱" );
String userName = TSUtility.readKeyBoard( 8, false );
this.userName = userName;
System.out.println( "賬戶修改成功啦ヽ(?゚▽゚)ノ" );
} else if (options.equals( "2" )) {
System.out.println( "請輸入新的密碼" );
String passWord = TSUtility.readKeyBoard( 8, false );
System.out.println( "密碼修改成功啦ヽ(?゚▽゚)ノ" );
} else if (options.equals( "3" )) {
System.out.println( "請輸入新的賬戶名稱" );
String userName = TSUtility.readKeyBoard( 8, false );
this.userName = userName;
System.out.println( "請輸入新的密碼" );
String passWord = TSUtility.readKeyBoard( 8, false );
this.passWord=passWord;
System.out.println( "賬戶和密碼都修改成功啦ヽ(?゚▽゚)ノ" );
} else if (options.equals( "4" )) {
System.out.println( "正在退出修改界面<( ̄ˇ ̄)/" );
TSUtility.loadSpecialEffects();
flag = false;
} else {
System.out.println( "請輸入1-4的整數哦 ̄へ ̄" );
}
}
}
}
團隊調度管理界面TeamView
import domain.Employee;
import domain.Programmer;
import service.NameListService;
import service.TeamException;
import service.TeamService;
import java.util.ArrayList;
public class TeamView {
private NameListService ListSvc = new NameListService();
private TeamService teamSvc = new TeamService();
ArrayList<Programmer[]> team = new ArrayList<>();
//進入界面
public void enterMainMenu() throws TeamException {
boolean loopFlag = true;
char key = 0;
do {
if (key != '1') {
listAllEmlpoyees();
}
System.out.println( "1-團隊串列 2-添加團隊成員 3-洗掉團隊成員 4-退出(若需添加下一團隊請退出此界面并選擇添加團隊 請選擇(1-4)" );
key = TSUtility.readMenuSelection();
System.out.println();
switch (key) {
case '1':
ListTeam();
break;
case '2':
addMember();
break;
case '3':
deleteMember();
break;
case '4':
System.out.println( "請確認是否要退出(Y/N)" );
char ch = TSUtility.readConfirmSelection();
if (ch == 'Y'){
team.add(teamSvc.getTeam());
teamSvc.clearTeam();
loopFlag = false;
}
break;
default:
System.out.println("輸入資訊有誤,請重新輸入");
break;
}
} while (loopFlag);
}
//顯示所有員工成員
private void listAllEmlpoyees() {
System.out.println( "\n-----------------------開發團隊調度軟體----------------------------\n" );
ArrayList<Employee> emps = ListSvc.getAllEmployees();
if (emps.size() == 0) {
System.out.println( "無客戶記錄," );
} else {
System.out.println( "ID\t\t\t姓名\t\t年齡\t\t工資\t\t職位\t\t狀態\t\t獎金\t\t股票\t\t領用設備" );
}
for (Employee e : emps) {//增強for回圈
System.out.println( " " + e );
}
System.out.println( "--------------------------------------------------------------------" );
}
//顯示開發團隊成員串列
private void ListTeam() {
System.out.println( "--------------團隊成員串列------------" );
Programmer[] team = teamSvc.getTeam();
if (team.length == 0) {
System.out.println( "開發團隊目前沒有成員" );
} else {
System.out.println( "TID\t\t姓名\t\t年齡\t工資\t職位\t獎金\t股票" );
}
//增強for回圈
System.out.println( "---------------------------------" );
for (Programmer p : team) {
System.out.println( " " + p.getDetailsForTeam() );
}
System.out.println( "----------------------------------" );
}
//添加成員到團隊
private void addMember() throws TeamException {
System.out.println( "-------------添加團隊成員-------------------" );
System.out.println( "請輸入要添加的成員ID" );
int id = TSUtility.readInt();
try {
Employee e = ListSvc.getEmployee( id );
teamSvc.addMember( e );
System.out.println( "添加成功" );
} catch (TeamException e) {
System.out.println( "添加失敗,原因是" + e.getMessage() );
}
//回車繼續
TSUtility.readReturn();
}
//從團隊中洗掉指定位置的成員
private void deleteMember() {
System.out.println( "--------------洗掉成員-------------" );
System.out.println( "請入要洗掉的員工TID" );
int TID = TSUtility.readInt();
if (TID < 1) {
try {
throw new TeamException( "不存在該員工的TID" );
} catch (TeamException e) {
System.out.println( e.getMessage() );
}
}
System.out.println( "請確認是否洗掉(Y/N)" );
char yn = TSUtility.readConfirmSelection();
if (yn == 'N') {
return;
}
try {
teamSvc.removeMember( TID );
System.out.println( "洗掉成功" );
} catch (TeamException e) {
System.out.println( "洗掉失敗,原因是" + e.getMessage() );
}
TSUtility.readReturn();
}
//加入并得到更多的團隊
public ArrayList<Programmer[]> getManyteam() throws TeamException {
boolean flag = true;
char key = 0;
do {
System.out.println( "*/*/*/*/*/*/*/" );
System.out.println( "*/ 團隊調度界面 */" );
System.out.println( "*/*/*/*/*/*/*/" );
System.out.println( "1-添加團隊 2-查看團隊 3-洗掉團隊 4-退出 請選擇(1-4)" );
key = TSUtility.readMenuSelection();
System.out.println();
switch (key) {
case '1':
enterMainMenu();
break;
case '2':
//加強for回圈該怎么用
System.out.println( "-----團隊串列-----" );
for (Programmer[] team : team) {
for (int i = 0; i < team.length; i++) {
System.out.println( team[i] );
}
System.out.println( "------------" );
teamSvc.clearTeam();
}
if (team.size() == 0) {
System.out.println( "當前無團隊,請先添加團隊" );
}
break;
case '3':
if (team.size() == 0) {
try {
throw new TeamException( "當前無團隊,請先添加團隊" );
} catch (TeamException e) {
System.out.println( e.getMessage() );
}
}
if (team.size() != 0) {
System.out.println( "請輸入要洗掉第幾個團隊" );
int num = TSUtility.readConfirmSelection();
if (num < team.size()) {
System.out.println( "請確認是否洗掉(Y/N);(Enter" );
char de = TSUtility.readConfirmSelection();
if (de == 'Y') {
team.remove( num - 1 );
} else {
System.out.println( "請考慮清楚" );
}
} else {
System.out.println( "沒有該團隊,請正常輸入!" + "目前團隊只有" + team.size() + "個" );
}
}
break;
case '4':
System.out.println( "是否退出(Y/N)" );
char yn = TSUtility.readConfirmSelection();
if (yn == 'Y') {
flag = false;
}
break;
default:
System.out.println( "輸入資訊有誤,請重新輸入" );
break;
}
} while (flag);
return team;
}
}
主界面IndexView
import domain.Programmer;
import service.NameListService;
import service.ProjectService;
import service.TeamException;
import java.util.ArrayList;
public class IndexView {
private final static Loginview loginVi = new Loginview();
private final static NameListService nameListSer = new NameListService();
private final static TeamView teamVi = new TeamView();
private final static ProjectService projectSer = new ProjectService();
private ArrayList<Programmer[]> manyTeam = null;
public void menu() throws TeamException {
boolean loopflag = true;
char key = 0;
System.out.println( "🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣" );
System.out.println( "🔣 🔣" );
System.out.println( "🔣 歡迎來到專案開發團隊分配管理軟體 🔣" );
System.out.println( "🔣 🔣" );
System.out.println( "🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣" );
System.out.println( "🐕" );
System.out.println( "🐕" );
System.out.println( "🐕" );
System.out.println( "🐕-----------<請您先進行登錄>-------------🐕" );
TSUtility.readReturn();
try {
loginVi.login();
} catch (InterruptedException e) {
System.out.println( e.getMessage() );
}
do {
System.out.println( "🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣" );
System.out.println( "🔣 🔣" );
System.out.println( "🔣 ~軟體主選單~ 🔣" );
System.out.println( "🔣 🔣" );
System.out.println( "🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣🔣" );
System.out.println( "🐻1. <用戶資訊修改> *" );
System.out.println( "🐘2. <開發人員管理> *" );
System.out.println( "🦁3. <開發團隊調度管理> *" );
System.out.println( "🐻4. <開發專案管理> *" );
System.out.println( "🦊5. <退出軟體> *" );
System.out.println( "?請選擇: " );
key = TSUtility.readMenuSelection();
switch (key) {
case '1':
try {
loginVi.update();
} catch (InterruptedException e) {
System.out.println( e.getMessage() );
}
break;
case '2':
try {
nameListSer.showEmployee();
} catch (InterruptedException e) {
System.out.println( e.getMessage() );
}
boolean loopFlagSec = true;
char keySec = 0;
do {
System.out.println( "🔣 ~開發人員管理主選單~ 🔣" );
System.out.println( "🐕1. <開發人員的添加> *" );
System.out.println( "🐖2. <開發人員的查看> *" );
System.out.println( "🐱3. <開發人員的修改> *" );
System.out.println( "🐂4. <開發人員的洗掉> *" );
System.out.println( "🐇5. <退出當前選單> *" );
System.out.println( "?請選擇: " );
keySec = TSUtility.readMenuSelection();
switch (keySec) {
case '1':
try {
nameListSer.addEmployee();
} catch (InterruptedException e) {
System.out.println( e.getMessage() );
}
break;
case '2':
try {
nameListSer.showEmployee();
} catch (InterruptedException e) {
System.out.println( e.getMessage() );
}
break;
case '3':
System.out.println( "請輸入要修改的員工ID" );
int i = TSUtility.readInt();
try {
nameListSer.modifyEmployee( i );
} catch (InterruptedException e) {
System.out.println( e.getMessage() );
}
break;
case '4':
System.out.println( "請輸入要洗掉的員工ID" );
int j = TSUtility.readInt();
nameListSer.delEmployee( j );
break;
case '5':
System.out.println( "確認是否要退出(Y/N)" );
char yn = TSUtility.readConfirmSelection();
if (yn == 'Y') {
loopFlagSec = false;
}
break;
default:
System.out.println( "輸入有誤,請重新輸入!" );
break;
}
} while (loopFlagSec);
break;
case '3':
manyTeam = teamVi.getManyteam();
break;
case '4':
boolean loopFlagThr = true;
char keyThr = 0;
do {
System.out.println( "🔣 ~開發專案管理主選單~ 🔣" );
System.out.println( "🐕1. <專案的添加> *" );
System.out.println( "🐖2. <專案分配開發團隊> *" );
System.out.println( "🐱3. <專案的查看> *" );
System.out.println( "🐂4. <專案的洗掉> *" );
System.out.println( "🐇5. <退出當前選單> *" );
System.out.println( "?請選擇: " );
keyThr = TSUtility.readMenuSelection();
switch (keyThr) {
case '1':
try {
projectSer.addProject();
} catch (InterruptedException e) {
System.out.println( e.getMessage() );
}
break;
case '2':
if(manyTeam.size()!=0){
for (Programmer[] pro : manyTeam) {//增強for回圈使用
projectSer.dealingPro( pro );
}
}else {
System.out.println("無團隊");
}
case '3':
try {
projectSer.showPro();
} catch (InterruptedException e) {
System.out.println( e.getMessage() );
}
break;
case '4':
System.out.println( "請輸入要洗掉的專案ID" );
int j = TSUtility.readInt();
projectSer.delPro( j );
break;
case '5':
System.out.println("確認是否退出(Y/N)");
char yn = TSUtility.readConfirmSelection();
if (yn=='Y'){
loopFlagThr =false;
}
break;
default:
System.out.println( "輸入有誤,請重新輸入" );
break;
}
} while (loopFlagThr);
break;
case '5':
System.out.println( "是否確認退出(Y/N)" );
char yn = TSUtility.readConfirmSelection();
if (yn == 'Y') {
loopflag = false;
}
break;
default:
break;
}
} while (loopflag);
}
public static void main(String[] args) throws TeamException {
new IndexView().menu();
}
}
遇到的BUG以及解決以及后續優化
1)載入界面注冊功能輸出問題:
問題如下:登錄賬號密碼錯誤時候會重復注冊
解決方法:將注冊寫在另一個方法,在登陸判定失敗時候才載入注冊界面
(詳細代碼見 Loginview)
2):1開發人員添加bug,洗掉序號沒能動態變化.
解決方法:使用動態ID,
for (int i = 0; i < employees.size(); i++) {
if (employees.get( i ).getId() == id) {
employees.remove( i );
for (i = id; i <= employees.size(); i++) {
//個人理解是不停的讓后面的序號-1覆寫前面的從而實作洗掉元素后前后序號排序正常,
employees.get( i - 1 ).setId( employees.get( i - 1 ).getId() - 1 );
}
flag = true;
}
}
3)在開發人員管理中添加的成員在團隊成員后,在團隊管理界面資料未能同步,
解決方法:將集合改為靜態并且,使用集合的isEmpty方法,
4)添加團隊成員失敗,沒有進行正確判定,直接拋出例外狀態

應該修改為:
if (!p.getStatus()) {
throw new TeamException( "該員工已經是某團隊成員" );
}
(其實是自己馬虎寫漏了!,后續找了半天…)
5)團隊成員tid排序紊亂,tid與id間隔不明顯無法精確顯示
//撰寫改變后的id
int i = 1;
for (int j = 0; j < total; j++) {
team[j].setMemberId( i++ );
}
增加間隔符增加顯示間隔
6)專案分配優化問題:
專案洗掉:如果洗掉正在被開發的專案未作詢問
修改如下:
//洗掉所選擇的專案
public void delPro(int id )throws TeamException{
boolean flag = false;
for (int i = 0; i < pro.size(); i++) {
if (pro.get( i ).getStatus()){
if (pro.get( i ).getProId()==id) {
pro.remove( i );
for (i = id; i < pro.size(); i++) {
pro.get( i - 1 ).setProId( pro.get( i - 1 ).getProId() - 1 );//對洗掉之后的序號的更新
}
flag = true;
}
}else {//如果我使用,洗掉正在開發的專案應拋出例外
throw new TeamException("該專案正在開發中");
}
}
就算在開發中我也要洗掉如何?
else {
// throw new TeamException("當前專案正在被開發,無法洗掉!");
System.out.println("當前專案正在被開發,無法洗掉!");
System.out.println("如果堅持洗掉請選擇1,退出選擇2");
boolean loopflag = true;
char key = TSUtility.readMenuSelection();
do {
switch (key){
case '1':
for (int j = 0; j < pro.size(); j++) {
if (pro.get( j ).getProId()==id){
pro.remove( j );
for (j = id ;j<pro.size();j++) {
pro.get( j-1 ).setProId( pro.get( j-1 ).getProId()-1 );
}
}
}
System.out.println("洗掉成功");
count--;
loopflag = false;
break;
case '2':
loopflag = false;
break;
default:
System.out.println("輸入有誤");
break;
}
}while (loopflag);
}
}
增加了一套回圈判斷
7)使用優化:
主要為輸出陳述句更加明顯,比如賬密位數標明,退出操作詢問,增刪改查明確提示之類的,設計一套程式之后除錯時要站在使用者的角度換位思考,有時候運行邏輯是對的但是并不符合使用者的使用習慣,
個人獲得的的成長思考
原本少年心氣馬虎追求速度,最后又是思路卡住功能實作不了改BUG一把辛酸淚,這個專案不僅讓我復習了許多知識,同時也讓我學到了很多java基礎語言的高級用法,不過我覺得最寶貴的是在這程序中,我學會了靜下心來去做事,認認真真的思考,道理在書上,而真正用行動去實踐是真正的考驗,希望以后的路上依然可以披荊斬棘高歌猛進,
嘿嘿都看到這里了點個贊再走呀!!!多謝多謝~~

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/397425.html
標籤:其他
