兄弟我純手打二百多行壹個多小時,希望對妳有用
這裏面有四個類,妳分別把四個類放到不同的java文件裏,然後運行就行了,結果如上圖,題中說的大部分功能已經實現
package?com.wg;
import?java.util.ArrayList;
import?java.util.List;
import?java.util.Scanner;
/**
*?1、使用Java編程思想編程; *?2、分紅、營業額與加班天數通過控制臺輸入獲得(加班天數不能超過8天); *?3、要求有總經理、部門主管和員工三個類以及相關屬性; *?4、要求員工的基本信息通過對象方法寫入; *?5、要求能在控制臺查看公司員工的所有信息(包括當月工資)。 *?6、可以通過控制臺添加、更改、刪除員工信息。(5分) * */public?class?Demo?{
public?static?void?main(String[]?args)?{
Scanner?sc?=?new?Scanner(System.in);
List<Employee>?listEm?=?new?ArrayList<Employee>();?
Employee?e1?=?new?Employee("李四",?25,?5000,?"財務部");
Employee?e2?=?new?Employee("王五",?22,?3000,?"市場部");
listEm.add(e1);
listEm.add(e2);
int?profit;//分紅
int?turnover;//營業額
int?workOverDate;//加班天數
int?temp,stemp,index;
while(true){
System.out.println("請輸入操作:");
System.out.println("1、添加新員工信息\t2、查看、更改、刪除員工信息\t3、錄入分紅、營業額、加班天數");
temp?=?sc.nextInt();
if(temp==1){
listEm.add(saveEmpioyee());
}else?if(temp==2){
editEmpioyee(listEm);
System.out.println("1、更改員工信息\t2、刪除員工信息\t3、返回");
stemp?=?sc.nextInt();
if(stemp==1){
System.out.println("請輸入需要更改員工的序號");
index?=?sc.nextInt();
System.out.println("1、員工姓名"+listEm.get(index).getName());
System.out.println("2、員工年齡"+listEm.get(index).getAge());
System.out.println("3、員工工資"+listEm.get(index).getSalary());
System.out.println("4、員工部門"+listEm.get(index).getDepartment());
System.out.println("請輸入需要更改內容的序號");
int?temp1?=?sc.nextInt();
if(temp1==1){
System.out.println("請輸入員工姓名");
listEm.get(index).setName(sc.next());
System.out.println("姓名修改成功!");
}else?if(temp1==2){
System.out.println("請輸入員工年齡");
listEm.get(index).setAge(sc.nextInt());
System.out.println("年齡修改成功!");
}else?if(temp1==3){
System.out.println("請輸入員工工資");
listEm.get(index).setSalary(sc.nextDouble());
System.out.println("工資修改成功!");
}else?if(temp1==4){
System.out.println("請輸入員工部門");
listEm.get(index).setDepartment(sc.next());
System.out.println("部門修改成功!");
}
}else?if(stemp==2){
System.out.println("請輸入需要刪除員工的序號");
index?=?sc.nextInt();
listEm.remove(index-1);
System.out.println("刪除成功!");
}else?if(stemp==3){
}
}else?if(temp==3){
System.out.println("請輸入分紅");
profit?=?sc.nextInt();
System.out.println("請輸入營業額");
turnover?=?sc.nextInt();
System.out.println("請輸入加班天數");
workOverDate?=?sc.nextInt();
//這裏面可以寫壹些操作
}
}
}
//添加員工
static?Employee?saveEmpioyee(){
Scanner?sc?=?new?Scanner(System.in);
Employee?em?=?new?Employee();
System.out.println("請輸入員工姓名:");
em.setName(sc.next());
System.out.println("請輸入員工年齡:");
em.setAge(sc.nextInt());
System.out.println("請輸入員工工資:");
em.setSalary(sc.nextDouble());
System.out.println("請輸入員工部門:");
em.setDepartment(sc.next());
System.out.println("錄入成功!");
return?em;
}
//查看、更改、刪除員工
static?void?editEmpioyee(List<Employee>?listEm){
for(int?i?=?0;i<listEm.size();i++){
System.out.println("序號:"+(i+1)+"\t員工姓名:"+listEm.get(i).getName()+"\t員工年齡:"+listEm.get(i).getAge()+
"\t員工工資:"+listEm.get(i).getSalary()+"\t員工部門:"+listEm.get(i).getDepartment());
}
}
}
package?com.wg;
class?Employee{
public?Employee()?{
}
public?Employee(String?name,int?age,double?salary,String?department)?{
this.name?=?name;
this.age?=?age;
this.salary?=?salary;
this.department?=?department;
}
private?String?name;
private?int?age;
private?double?salary;//工資
private?String?department;//部門
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?getDepartment()?{
return?department;
}
public?void?setDepartment(String?department)?{
this.department?=?department;
}
}
package?com.wg;
public?class?Manager?{private?String?name;
private?int?age;
private?double?salary;//工資
private?String?department;//部門
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?getDepartment()?{
return?department;
}
public?void?setDepartment(String?department)?{
this.department?=?department;
}
}
package?com.wg;
public?class?Charger?{private?String?name;
private?int?age;
private?double?salary;//工資
private?String?department;//部門
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?getDepartment()?{
return?department;
}
public?void?setDepartment(String?department)?{
this.department?=?department;
}
}