在外層迭代日期,
創(chuàng)新互聯(lián)是一家專業(yè)提供宜君企業(yè)網(wǎng)站建設(shè),專注與做網(wǎng)站、成都網(wǎng)站建設(shè)、H5場景定制、小程序制作等業(yè)務(wù)。10年已為宜君眾多企業(yè)、政府機構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)的建站公司優(yōu)惠進(jìn)行中。
在Action中聲明一個沖御MapString,Object?map
寫好getter,setter
每條考勤記錄都put進(jìn)map中,把考勤記錄的日期字符串yyyy-MM-dd作為key
將key和迭帆判爛代的當(dāng)前日期比較,如果一致就輸出內(nèi)容。態(tài)漏
jsp頁面如下代碼:
有疑問再聯(lián)系我!
public?class?Test06?{
static?ListStudent_Status?list_Student_Status?=?new?ArrayListStudent_Status();
static?ListStudent?list_Student?=?new?ArrayListStudent();
static?ListStatus?list_Studus?=?new?ArrayListStatus();
static?Scanner?scanner?=?new?Scanner(System.in);
public?Test06()?{
list_Studus.add(new?Status("001",?"病假"));
list_Studus.add(new?Status("002",?"產(chǎn)假"));
list_Studus.add(new?Status("003",?"事假"));
list_Studus.add(new?Status("004",?"婚假"));
list_Student.add(new?Student("001",?"張三"));
list_Student.add(new?Student("002",?"李四"));
list_Student.add(new?Student("003",?"王五"));
list_Student.add(new?Student("004",?"劉杰"));
list_Student.add(new?Student("005",?"陳朋"));
list_Student.add(new?Student("006",?"趙明明"));
list_Student.add(new?Student("007",?"羅四海"));
list_Student.add(new?Student("008",?"謝一刀"));
list_Student_Status.add(new?Student_Status("001",?list_Student.get(0),
list_Studus.get(0)));
list_Student_Status.add(new?Student_Status("002",?list_Student.get(1),
list_Studus.get(0)));
鉛纖?????list_Student_Status.add(new?Student_Status("003",?list_Student.get(2),
list_Studus.get(1)));
list_Student_Status.add(new?Student_Status("004",?list_Student.get(3),
陸雹??????????????list_Studus.get(0)));
list_Student_Status.add(new?Student_Status("005",?list_Student.get(4),
list_Studus.get(2)));
list_Student_Status.add(new?Student_Status("006",?list_Student.get(5),
list_Studus.get(0)));
list_Student_Status.add(new?Student_Status("007",?list_Student.get(6),
list_Studus.get(3)));
list_Student_Status.add(new?Student_Status("008",?list_Student.get(7),
list_Studus.get(0)));
}
public?static?void?main(String[]?args)?{
new?Test06();
showHelp();
doMothed();
}
public?static?void?doMothed()?{
System.out.println("請選擇你要操作的類型??1-按學(xué)號查詢考勤??2-按考勤態(tài)早激帆度id杳學(xué)生");
System.out.println("請輸入...");
int?num?=?scanner.nextInt();
switch?(num)?{
case?1:
Find_1();
break;
case?2:
Find_2();
break;
default:
showHelp();
break;
}
doMothed();
}
public?static?void?Find_2()?{
System.out.println("請輸考勤類型代號:");
String?ids2?=?scanner.next();
ListStudent?list_temp?=?findStudentsByStatusID(ids2);
System.out.println("當(dāng)前請??"?+?findByStatusID(ids2).status?+?"?的人員有:");
for?(Student?student?:?list_temp)?{
System.out.println(student.getName());
}
}
public?static?void?Find_1()?{
System.out.println("請輸入學(xué)生學(xué)號:");
String?ids?=?scanner.next();
ListStudent_Status?list_ss?=?GetByStudentID(ids);
System.out.println("當(dāng)前學(xué)生為:??"?+?FindByid(ids).getName());
for?(Student_Status?student_Status?:?list_ss)?{
System.out.println("時間:?"?+?student_Status.getDate()?+?"????姓名:?"
+?student_Status.getStudent().getName()?+?"??事由:?"
+?student_Status.getStatus().status);
}
}
public?static?void?showHelp()?{
System.out.println("??????????學(xué)生信息列表");
System.out.println("********************************");
System.out.println("ID?????????????姓名");
for?(Student?student?:?list_Student)?{
System.out.println(student.getId()?+?"????????????"
+?student.getName());
}
System.out.println("********************************");
System.out.println("考勤狀態(tài)表");
System.out.println("********************************");
System.out.println("ID?????????????狀態(tài)");
for?(Status?status?:?list_Studus)?{
System.out.println(status.id?+?"????????????"?+?status.status);
}
System.out.println("********************************");
}
public?static?Status?findByStatusID(String?ids)?{
for?(Status?status?:?list_Studus)?{
if?(status.id.equals(ids))
return?status;
}
return?null;
}
public?static?Student?FindByid(String?id)?{
for?(Student?ss?:?list_Student)?{
if?(ss.getId().equals(id))?{
return?ss;
}
}
return?null;
}
//?添加考勤
public?void?Add_Student_Status(Student_Status?ss)?{
list_Student_Status.add(ss);
}
//?按考勤類型查人員
public?static?ListStudent?findStudentsByStatusID(String?id)?{
ListStudent?list?=?new?ArrayListStudent();
for?(Student_Status?ss?:?list_Student_Status)?{
if?(ss.getStatus().id.equals(id))?{
list.add(ss.getStudent());
}
}
return?list;
}
//?按學(xué)號查詢考勤
public?static?ListStudent_Status?GetByStudentID(String?id)?{
Student?student?=?FindByid(id);
return?student.getStudent_Status();
}
//?學(xué)生對象
class?Student?{
String?id;
String?name;
public?Student(String?id,?String?name)?{
this.name?=?name;
this.id?=?id;
}
public?String?getId()?{
return?id;
}
public?String?getName()?{
return?name;
}
public?ListStudent_Status?getStudent_Status()?{
ListStudent_Status?list1?=?new?ArrayListStudent_Status();
for?(Student_Status?ss?:?list_Student_Status)?{
if?(ss.getStudent().getId().equals(getId()))?{
list1.add(ss);
}
}
return?list1;
}
}
//?考勤對象
class?Status?{
String?id;
String?status;
public?Status(String?id,?String?status)?{
this.status?=?status;
this.id?=?id;
}
}
class?Student_Status?{
String?id;
Date?date;
Student?student;
Status?status;
public?Student_Status(String?id,?Student?student,?Status?status)?{
this.id?=?id;
this.date?=?new?Date();
this.student?=?student;
this.status?=?status;
}
public?String?getId()?{
return?id;
}
public?Date?getDate()?{
return?date;
}
public?Student?getStudent()?{
return?student;
}
public?Status?getStatus()?{
return?status;
}
}
}
簡單,第一步:寫一個員工類 第二步:寫一個員工操作類 第三步:寫一個測試主函數(shù) 第四步:寫一個數(shù)據(jù)庫操作類給你一個寫過的代碼,你自己參照著看看吧:在不行加我qq:1464388632 (給我分在加,否則不加)=================================測試類Application.java=================================import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;public class Application { public static void main(String[] args) throws Exception{
EmpManage em=new EmpManage();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String EmpNo;
String name;
double salary;
while(true)
{
String optype;
System.out.println("請輸入你選的操作");
System.out.println("1:創(chuàng)察咐建用胡頃戶");
System.out.println("2:查找用戶信息");
System.out.println("3:顯示所褲沒陸有用戶信息");
System.out.println("4: 保存到文件");
optype=br.readLine();
if(optype.equals("1"))
{
System.out.println("請輸入用戶ID");
EmpNo=br.readLine();
System.out.println("請輸入用戶名");
name=br.readLine();
System.out.println("請輸入用戶工資");
salary=Double.parseDouble( br.readLine());
Employee ee=new Employee(EmpNo,name,salary);
em.addEmployee(ee);
}else if(optype.equals("2"))
{
System.out.println("請輸入用戶ID");
EmpNo=br.readLine();
em.findEmployee(EmpNo);
}else if(optype.equals("3"))
{
em.allDisplay();
}else if(optype.equals("4")){
em.saveFile();
}
} }}
=================================員工類。Employee.java=================================import java.io.*;
public class Employee implements Serializable{
private String EmpNo;
private String name;
private double salary;
public Employee(String EmpNo,String name,double salary)
{
this.EmpNo=EmpNo;
this.name=name;
this.salary=salary;
} public String getEmpNo() {
return EmpNo;
} public void setEmpNo(String empNo) {
EmpNo = empNo;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public double getSalary() {
return salary;
} public void setSalary(double salary) {
this.salary = salary;
}
}
=================================員工操作類。EmpManage.java================================= import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;public class EmpManage {
ArrayList al=new ArrayList();
//創(chuàng)建添加一個新用戶
Employee ee=null;
public EmpManage()
{
try {
FileInputStream fis=new FileInputStream("data.ser");
ObjectInputStream ois=new ObjectInputStream(fis);
ee= (Employee)ois.readObject();
while(ee!=null)
{
al.add(ee);
System.out.println(al.size());
ee= (Employee)ois.readObject();
System.out.println("此處安全");
}
System.out.println("此處安全");
ois.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void addEmployee(Employee ee)
{
al.add(ee);
}
//通過員工號查找員工對應(yīng)信息
public void findEmployee(String EmpNo)
{
for(int i=0;ial.size();i++)
{
if(((Employee)al.get(i)).getEmpNo().equals(EmpNo))
{
System.out.println("你所查找的用戶已經(jīng)查到 信息如下:");
System.out.println("姓名:"+((Employee)al.get(i)).getName());
System.out.println("工號:"+((Employee)al.get(i)).getEmpNo());
System.out.println("工資:"+((Employee)al.get(i)).getSalary());
}
}
}
public void saveFile() throws Exception
{
FileOutputStream fos=new FileOutputStream("data.ser");
ObjectOutputStream oos=new ObjectOutputStream(fos);
for(int i=0;ial.size();i++)
{
Employee ee=(Employee) al.get(i);
oos.writeObject(ee);
System.out.println("保存成功");
}
oos.close();
}
//顯示所有用戶信息
public void allDisplay()
{
for(int i=0;ial.size();i++)
{
Employee ee=(Employee) al.get(i);
System.out.println("====================");
System.out.println("工號:"+ee.getEmpNo());
System.out.println("名字:"+ee.getName());
System.out.println("工資:"+ee.getSalary());
System.out.println("====================");
}
}
}