⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 studentdao.java

📁 一个java源码,学籍管理系统的,我老师的,我还没看呢,该让我下东西了吧
💻 JAVA
字号:
/*
 * Created on 2005-4-9
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package dao;
import java.io.*;
import java.util.*;
import vo.*;
import exception.*;
/**
 * @author ywl
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class StudentDAO {
	private ArrayList studentList=new ArrayList();
	public StudentDAO(){
		//init();
	}
	public void addNew(StudentVo student) throws DuplicateException{
		boolean duplicate=false;
		Iterator itr=studentList.iterator();
		while(itr.hasNext()){
			StudentVo stud=(StudentVo)itr.next();
			if(stud.getNum().equals(student.getNum()))
				duplicate=true;	
		}
		if(duplicate)
			throw(new DuplicateException("duplicate"));
		else
			studentList.add(student);		
			
	}
	public void update(StudentVo student)throws NotFoundException{
		boolean foundIt=false;
		String num=student.getNum();
		Iterator itr=studentList.iterator();
		while(itr.hasNext()){
			StudentVo stud=(StudentVo)itr.next();
			if(stud.getNum().equals(num)){
				foundIt=true;
				itr.remove();
				break;	
			}
		}
		if(foundIt)
			studentList.add(student) ;
		else
			throw(new NotFoundException("not found"));
	}
	public void delete(StudentVo student)throws NotFoundException{
		boolean foundIt=false;
		String num=student.getNum();
		Iterator itr=studentList.iterator();
		while(itr.hasNext()){
			StudentVo stud=(StudentVo)itr.next();
			if(stud.getNum().equals(num)){
				foundIt=true;
				itr.remove();
				break;
			}		
		}
		if(foundIt)
			return ;
		else
			throw(new NotFoundException("not found"));
	}
	public StudentVo search(String num) throws NotFoundException{
		StudentVo stud=null;
		boolean foundIt=false;
		Iterator itr=studentList.iterator();
		while(itr.hasNext()){
			stud=(StudentVo)itr.next();
			if(stud.getNum().equals(num))
				foundIt=true;	
		}
		if(foundIt)
			return stud;
		else
			throw(new NotFoundException("not found"));
			
	}
	public void init(){
		studentList.add(new StudentVo("200360101","a",21));
		studentList.add(new StudentVo("200360102","b",22));
		studentList.add(new StudentVo("200360103","c",23));
		studentList.add(new StudentVo("200360104","d",24));
	}
	public void init(String fileName){
		FileReader fr=null;
		BufferedReader br=null;
		String str=null;
		try{
			fr=new FileReader(fileName);
			br=new BufferedReader(fr);
			while((str=br.readLine())!=null){
				
				String[] strLine=null;
				try{
					strLine=str.split(",");
				}
				catch(Exception e){
					
				}
				finally{
					
				}
				String num=strLine[0];
				String name=strLine[1];
				int age=Integer.parseInt(strLine[2]);
				StudentVo stud=new StudentVo(num,name,age);
				studentList.add(stud);
			}
			br.close();	
			fr.close();
		}
		catch(FileNotFoundException e){
			System.out.println("erro  "+e);
		}
		catch(IOException e){
			System.out.println("Erro  "+e);
		}
		
	}
	public boolean isExit(StudentVo student){
		boolean ok=false;
		Iterator itr=studentList.iterator();
		while(itr.hasNext()){
			StudentVo stud=(StudentVo)itr.next();
			if(stud.getNum().equals(student.getNum()))
				ok=true;	
		}
		return ok;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -