1.定义公司成员作为父类
package tEAM;
public class Person {
private String ID;
private String age;
private String wages;
private String position;
private String state;
private String bonus;
private String device;
private String name;
private String doc;
public String getDoc() {
return doc;
}
public void setDoc(String doc) {
this.doc = doc;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public String getBonus() {
return bonus;
}
public String getDevice() {
return device;
}
public String getID() {
return ID;
}
public String getPosition() {
return position;
}
public String getState() {
return state;
}
public String getWages() {
return wages;
}
public void setAge(String age) {
this.age = age;
}
public void setBonus(String bonus) {
this.bonus = bonus;
}
public void setDevice(String device) {
this.device = device;
}
public void setID(String ID) {
this.ID = ID;
}
public void setPosition(String position) {
this.position = position;
}
public void setState(String state) {
this.state = state;
}
public void setWages(String wages) {
this.wages = wages;
}
public void show(){
System.out.print(this.ID+" " );
System.out.print(this.name+" " );
System.out.print(this.position+" " );
System.out.print(this.age+" " );
System.out.print(this.wages+" " );
System.out.print(this.state+" " );
System.out.print(this.bonus+" " );
System.out.print(this.doc+" " );
System.out.println(this.device+" " );
}
}
2.定义团队成员作为子类
package tEAM;
public class s_team extends Person{
private String TID;
public String getTID() {
return TID;
}
public void setTID(String TID) {
this.TID = TID;
}
public void show(){
System.out.print(getTID() +"/"+getID()+" " );
System.out.print(getName()+" " );
System.out.print(getPosition()+" " );
System.out.print(getAge()+" " );
System.out.print(getWages()+" " );
System.out.print(getState()+" " );
System.out.print(getBonus()+" " );
System.out.print(getDoc()+" " );
System.out.println(getDevice()+" " );
}
}
3.主程序
package tEAM;
import java.util.ArrayList;
import java.util.Scanner;
public class run {
public static void main(String[] args) {
ArrayList<Person> array=creat();
ArrayList<s_team> array_team=new ArrayList<>();
ArrayList <s_team> array_all=new ArrayList<>();
flash(array);
int lable=0;
while(lable==0){
lable=0;
shower(array) ;
System.out.println("---------------------------------------------------------------------");
System.out.println("1-团队列表 2-添加团队成员 3-删除团队成员 4-退出 请选择(1-4)" );
Scanner s =new Scanner(System.in);
int s1=s.nextInt();
if((s1<0)||(s1>4))
{
System.out.println("输入有误,请重新输入1-4之间的整数");
}
else{switch(s1){
case 1:int label1=list(array_team);
if(label1 ==0){lable=0;}
else{lable=1;}
case 2:int label2=1;
while(label2==1){int label_2=add(array_team,array,array_all);
System.out.println("是否继续添加(Y/N)?");
if (label_2==1){label2=1;}
Scanner k=new Scanner(System.in);
String chos=k.nextLine() ;
if(chos.equals("y")){label2 =1;
}
else {lable=0;label2 =0;}
}break;
case 3:int label3=1;
if (array_team .size()==0){
System.out.println("暂无成员,请先添加");
System.out.println("请按回车键继续");
Scanner k=new Scanner(System.in);
String chos=k.nextLine() ;
}else{
while(label3 ==1){
team_list(array_team);
System.out.println("请输入要删除的成员TID");
Scanner k=new Scanner(System.in);
String chos=k.nextLine() ;
label3 =del(array ,array_team ,array_all ,chos);
if(label3 ==0){System.out.println("删除成功!");
int size=array_team.size();
if (size==0){
System.out.println("成员列表已经空啦,请添加后删除");
System.out.println("按回车键继续");
Scanner A=new Scanner(System.in) ;
String l=A.nextLine() ;
break;
}
}
System.out.println("是否继续删除(Y/N)");
String o=k.nextLine() ;
if(o.equals("y") )
{
label3 =1;
}
else{label3 =0;}
}}break;
case 4:System .exit(0);
}
}
}
}
public static void set(Person p,String a,String b,String c,String d,String e,String f,String g,String h,String i)
{p.setID(a);
p.setName(b);
p.setAge(c);
p.setWages(d);
p.setPosition(e);
p.setState(f);
p.setBonus(g);
p.setDoc(h);
p.setDevice(i);
}
public static void prin(){
System.out.print("ID"+" " );
System.out.print("姓名"+" " );
System.out.print("职位"+" " );
System.out.print("年龄"+" " );
System.out.print("工资"+" " );
System.out.print("状态"+" " );
System.out.print("奖金"+" " );
System.out.print("股票"+" " );
System.out.println("领用设备"+" " );
}
public static void flash(ArrayList <Person> array){
System.out.println("---------------------------开发者团队调度软件----------------------------");
prin();
set(array.get(0),"1 ","马云","22","3000.0"," ","","","","");
array.get(0).show();
set(array.get(1),"2 ","马化腾","32","18000.0","架构师","FREE","15000.0","2000","联想T4");
array.get(1).show();
set(array.get(2),"3 ","李彦宏","23","7000.0 ","程序员","FREE"," "," "," 戴尔");
array.get(2).show();
set(array.get(3),"4 ","刘强东","24","7500.0 ","程序员","FREE"," "," "," 戴尔");
array.get(3).show();
set(array.get(4),"5 ","雷军 ","28","10000.0","设计师","FREE","5000.0 "," ","激光佳能");
array.get(4).show();
set(array.get(5),"6 ","任志强","22","6800.0 ","程序员","FREE"," "," "," 华硕");
array.get(5).show();
set(array.get(6),"7 ","柳传志","28","10800.0","设计师","FREE","5200.0 "," ","华硕");
array.get(6).show();
set(array.get(7),"8 ","杨元庆","30","19800.0","架构师","FREE","15000.0","2500","爱普生");
array.get(7).show();
set(array.get(8),"9 ","史玉柱","26","9800.0 ","设计师","FREE","5500.0 "," ","惠普m6");
array.get(8).show();
set(array.get(9),"10","丁磊 ","21","6600.0 ","程序员","FREE"," "," "," 戴尔");
array.get(9).show();
set(array.get(10),"11","张朝阳","25","7100.0 ","程序员","FREE"," "," "," 华硕");
array.get(10).show();
set(array.get(11),"12","杨致远","27","9600.0 ","设计师","FREE","4800.0 "," ","惠普m6");
array.get(11).show();
System.out.println("---------------------------------------------------------------------");
System.out.println("1-团队列表 2-添加团队成员 3-删除团队成员 4-退出 请选择(1-4)" );
}
public static ArrayList<Person> creat()
{ ArrayList<Person> array=new ArrayList<>();
for(int i=0;i<12;i++)
{
Person p=new Person();
array.add(p);
}
return array;}
public static int list(ArrayList<s_team> sts)
{
int size=sts.size();
int m=0;
if(size==0){
System.out.println("暂无团队成员,请先添加后再查看");
System.out.println("请按回车键继续");
Scanner a=new Scanner(System.in);
String l=a.nextLine();
return m;
}else{System.out.println("---------------------------团队成员列表----------------------------");
System.out.print("TID/ID" +" ");
System.out.print("姓名"+" " );
System.out.print("职位"+" " );
System.out.print("年龄"+" " );
System.out.print("工资"+" " );
System.out.print("状态"+" " );
System.out.print("奖金"+" " );
System.out.print("股票"+" " );
System.out.println("领用设备"+" " );
for(int i=0;i<size;i++)
{sts.get(i).show(); }
return 1;}
}
public static int add(ArrayList<s_team> sts,ArrayList<Person> sp,ArrayList <s_team> array_all)
{
System.out.println("---------------------------添加成员----------------------------");
System.out.println("请输入要添加成员的ID");
Scanner s=new Scanner(System.in);
int id=s.nextInt();
id=id-1;
if((id>=0)&&(id<12))
{ int a=chat(sp,sts,id);
if (a==0){
add_method(sts,sp,array_all ,id) ;
return 0;}
else {
return 1;
}
}
else{
System.out.println("id越界,请重新添加");
return 1;
}
}
public static void add_method(ArrayList<s_team> sts,ArrayList<Person> sp,ArrayList <s_team> array_all,int id)
{
Person a=sp.get(id);
s_team b=new s_team();
b.setAge(a.getAge());
b.setName(a.getName());
b.setBonus(a.getBonus());
b.setDevice(a.getDevice());
b.setDoc(a.getDoc());
b.setPosition(a.getPosition());
b.setState("BUSY");
b.setWages(a.getWages());
b.setID(a.getID());
sts.add(b);
array_all .add(b);
String TID;
TID=String .valueOf(array_all.size());
b.setTID(TID);
sp.get(id).setState("BUSY") ;
shower(sp);
team_list(sts);
System.out.println("添加成功!");}
public static int chat(ArrayList<Person> sp,ArrayList<s_team> sts,int id)
{ int a=0;
int b=0;
int c=0;
if(sp.get(id).getState().equals("BUSY")){
for(int i=0;i<sts.size();i++)
{if (sts.get(i).getID() .equals(sp.get(id).getID()))
{
System.out.println("该成员已在本团队中,请重新选择");
a=1;
}
if(!(sts.get(i).getID().equals(sp.get(id).getID()))){
System.out.println("该成员已经在其他开发团队中,请重新选择");
a=1;
}
}}
if((!sp.get(id).getPosition().equals("程序员"))&&(!sp.get(id).getPosition().equals("架构师"))&&(!sp.get(id).getPosition().equals("设计师")))
{
System.out.println("非开发人员,请重新选择");
a=1;
}
if((sp.get(id).getState().equals("REST")))
{
System.out.println("该成员正在休假,请重新选择");
a=1;
}
switch (sp.get(id).getPosition() )
{
case "架构师":
for(int i=0;i<sts.size();i++){
if (sts.get(i).getPosition() .equals("架构师"))
{if(sts.get(i).getPosition().equals(sp.get(id).getPosition()))
{System.out.println("该成员已在本团队中,请重新选择");
a=1;}
else{System.out.println("团队中架构师已满,请重新选择");
a=1;}
}
}
case "设计师":
for(int i=0;i<sts.size();i++){
if (sts.get(i).getPosition() .equals("设计师"))
{ b++;
if(b>1){
System.out.println("团队中设计师已满,请重新选择");
a=1;}
}
}
case "程序员":
for(int i=0;i<sts.size();i++){
if (sts.get(i).getPosition() .equals("程序员"))
{ c++;
if(c>2){
System.out.println("团队中程序员已满,请重新选择");
a=1;}
}
}
}
return a;
}
public static ArrayList<Person> change(ArrayList<Person> a,ArrayList<s_team> b)
{if(b.size()>0) {
for(int i=0;i<a.size();i++)
{
for (int j = 0; j < b.size(); j++) {
if (a.get(i).getID().equals(b.get(j).getID())) {
a.set(i, a.get(i)).setState("BUSY");
}
}
}
}
return a; }
public static void shower(ArrayList<Person> p)
{System.out.println("---------------------------开发者团队调度软件----------------------------");
prin();
for(int i=0;i<p.size();i++)
{p.get(i).show();}
}
public static int del (ArrayList<Person> a,ArrayList<s_team> b,ArrayList <s_team> c,String TID){
int tID=Integer.parseInt(TID)-1;
if(tID>b.size()-1 )
{
System.out.println("请输入TID在1到"+(b.size()-1)+"的整数" );
return 1;
}
else{String ID=b.get(tID).getID();
b.remove(tID) ;
for (int i=0;i<a.size() ;i++)
{
if(a.get(i).getID() .equals(ID) )
{
a.get(i).setState("FREE");
}
}
team_list(b) ;
return 0; }
}
public static void team_list(ArrayList<s_team> sts)
{ System.out.println("---------------------------团队成员列表----------------------------");
System.out.print("TID/ID" +" ");
System.out.print("姓名"+" " );
System.out.print("职位"+" " );
System.out.print("年龄"+" " );
System.out.print("工资"+" " );
System.out.print("状态"+" " );
System.out.print("奖金"+" " );
System.out.print("股票"+" " );
System.out.println("领用设备"+" " );
for(int p=0;p<sts.size() ;p++)
{sts.get(p).show();}}
}