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

📄 studymanager.java

📁 一个学籍管理系统。
💻 JAVA
字号:
import java.util.*;
import java.io.*;

//Abstract base class of Event
//Command Patterns
abstract class Event
{
	abstract public void execute();
	abstract public String description();
}


//To Manage the GraStudent and
//the BachlorStudent
public class StudyManager
{
	public StudyManager()
	{}
	
	//Inner Classes
    public class BachlorStudentEvent extends Event
	{
		private BachlorStudent _student;
		Teacher teacher=new Teacher();
		public BachlorStudentEvent(AbstractStudent student)
		{
			_student=(BachlorStudent)student;								
		}
		public void execute()
		{
						
			_student.selectTeacher(teacher);					
		}
		public String description()
		{
			return "Event:BachlorStudent "+_student.getName()+" Select Teacher "+teacher.getName();
		}
	
	}
	public class GraStudentEvent extends Event
	{
		GraStudent _student;
		public GraStudentEvent(AbstractStudent student)
		{
			_student=(GraStudent)student;		
		}
		public void execute()
		{
			String department=new String("Department");
			_student.selectDepartment(department);
		}
		public String description()
		{
			return "Event:GraStudent Select Department";
		}
	}
	
		
	private static void display()
	{
		System.out.println("Student Manage System");
		System.out.println("==Command List==\n"+
		                     "A :Show All Student Information\n"+
		                     "S :Searh Student\n");
		
	}
	
	private  static void showAll(Iterator it)
	{
		while(it.hasNext())
		{
			AbstractStudent mystudent=(AbstractStudent)it.next();
			mystudent.showStudentInfo();			
		}
	}
	
	private static void searchStudent(Iterator it,String name) throws StudentNotFoundException
	{
		while(it.hasNext())
		{
			AbstractStudent mystudent=(AbstractStudent)it.next();	
			if(mystudent._name.equals(name))
			{
				mystudent.showStudentInfo();
				return;
			}	
		}
		throw new StudentNotFoundException(name);
	}
	
	
	//For testing the program	
	public static void main(String args[])
	{
		StudyManager manager=new StudyManager();
		Event event;		
		List mycollection=new ArrayList();
		ConcreteStudentManager csmanager=new ConcreteStudentManager();
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		String name=new String();
		String c=null;
		
		mycollection.add(new BachlorStudent("Greece"));
		mycollection.add(new BachlorStudent("Wolfgang"));
		mycollection.add(new BachlorStudent("Jenny"));
		mycollection.add(new BachlorStudent("Tony"));
		mycollection.add(new BachlorStudent("Sam"));
		mycollection.add(new GraStudent("Blare"));
		mycollection.add(new GraStudent("Bush"));
		mycollection.add(new GraStudent("Markus"));
		mycollection.add(new GraStudent("Beck"));
		mycollection.add(new GraStudent("Jack"));
		
		for(int i=0;i<mycollection.size();i++)
		{
			AbstractStudent student=(AbstractStudent)mycollection.get(i);
			if(student instanceof GraStudent)
			{
				Event eve=manager.new GraStudentEvent(student);
				eve.execute();												
			}			
			else if(student instanceof BachlorStudent)
			{
				Event eve=manager.new BachlorStudentEvent(student);
				eve.execute();
			
			}
			else
			{
				System.out.println("Error:Invalid Class!");
			}
		}
		Iterator it=mycollection.iterator();
		
	
		StudyManager.display();
		
		try
		{
			c=in.readLine();
		}
		catch(Exception e){}
		
			
		switch(Character.toUpperCase(c.charAt(0)))
		{
			case 'A':
			StudyManager.showAll(it);
			break;
			case 'S':
			{
				System.out.print("Student Name: ");
				try
				{
					in.skip(0);
					name=in.readLine();
				}
				catch(Exception e)
				{
					System.out.println("Error Input Stream!");
				}
				System.out.println("Result:\n");
				try
				{
					StudyManager.searchStudent(it,name);
			    }
			    catch(StudentNotFoundException e)
			    {
				   System.out.println(e.toString());
			    }
		    }
			break;
			default:
			System.out.println("Error Command!");
			break;
		}
	 	//manager.run();		
	}
}

⌨️ 快捷键说明

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