java大作业——选课系统

一:代码目录:
在这里插入图片描述

二:代码实现及解析:
biz包里的三个类:
CourseBiz.java

package biz;
import java.util.*;
import java.io.*;
import dao.*;
import entity.Course;


public class CourseBiz {
	
     public static void print() throws FileNotFoundException{
    	 CourseDao courseDao = CourseDao.getInstance();
//    	 CourseDao courseDao = new CourseDao();
    	 Set keySet = courseDao.getAllEntities().keySet();
    	 Iterator it = keySet.iterator();
    	     System.out.println("------------大二上学期可选课程列表------------");
    	 while(it.hasNext()){
    		 Object key = it.next();
    		 Course value = (Course)courseDao.getAllEntities().get(key);
    		 System.out.println("*课程编号:"+key+"------课程名称:"+value.getCourseName()+"-----课程学分:"+value.getCourseGrade()+"*");
    	 }
    	     System.out.println("----------------------------------------");
     }
}

SCBiz.java

package biz;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Scanner;

import dao.CourseDao;
import dao.SCDao;
import dao.StudentDao;
import entity.Course;
import entity.IEntity;
import entity.SC;
import entity.Student;

public class SCBiz{
	
//	CourseDao courseDao = CourseDao.getInstance();
	private SC sc;
  
	public void save() throws IOException{
		SCDao sCDao = SCDao.getInstance();
		sCDao.update1();
	}
	
  public void selection() throws IOException{
	  SCDao scDao = SCDao.getInstance();
	  CourseBiz courseBiz = new CourseBiz();
	  courseBiz.print();
	  Scanner scan = new Scanner(System.in);
	  System.out.println("请输入您的学号,以便我们确认是您本人操作:");
	  String studentNo = scan.nextLine();
	  System.out.println("请输入您所要选择的课程编号:");
	  String courseNo = scan.nextLine();
	  
	  sc = (SC)scDao.getEntity(studentNo);
	  if(sc==null) {
		  sc = new SC();
		  sc.setStudentNo(studentNo);
		  StringBuffer courseNo1 = new StringBuffer();
		  courseNo1.append(courseNo+",");
		  sc.setCourseNo(courseNo1);
	      CourseDao courseDao = (CourseDao)CourseDao.getInstance();
	      Course course = (Course)courseDao.getEntity(courseNo);
	      int grade = course.getCourseGrade();
		  sc.setGrade(grade);
		  scDao.insert(sc);
		  save();
	  }else {
		  CourseDao courseDao = CourseDao.getInstance();
		  StringBuffer s = new StringBuffer();
		  StringBuffer s1 = new StringBuffer();
		  s =sc.getCourseNo();
		  s1 =sc.getCourseNo();
		  String [] arr = s1.toString().split(",");
		  int flag=0;
		  for(int i=0;i<arr.length;i++) {
			  if(arr[i].equals(courseNo)) flag=1;
		  }
		  if(flag==0) {
			  s.append(courseNo+",");
		  sc.setCourseNo(s);
		  
		  
		  int a = sc.getGrade();
		  a=a+(((Course)courseDao.getEntity(courseNo)).getCourseGrade());
		  sc.setGrade(a);
		  scDao.insert(sc);
		  save();
		  }
		  else System.out.println("抱歉,您已经选过该门课程,不能重复选择!");
		  
	  } 
 }
 
  public void withdrawal() throws IOException{
	  SCDao scDao = SCDao.getInstance();
	  CourseDao courseDao = CourseDao.getInstance();
	  CourseBiz courseBiz = new CourseBiz();
	  courseBiz.print();
	  Scanner scan = new Scanner(System.in);
	  
	  System.out.println("请输入您的学号,以便我们确认是您本人操作:");
	  String studentNo = scan.nextLine();
	  System.out.println("请输入您所要退选的课程编号:");
	  String courseNo = scan.nextLine();
	  
	  sc = (SC)scDao.getEntity(studentNo);
	  StringBuffer s = new StringBuffer();
	  s = sc.getCourseNo();
	  String[] arr = s.toString().split(",");
	  int flag=0;
	  for(int i=0;i<arr.length;i++) {
		  if(arr[i].equals(courseNo)) flag=1;
	  }
	  if(flag==0) {
		  System.out.println("您还没有选过该门课程,不能进行退选操作!");
	  }
	  else {
		 s.delete(0, s.length());
		 for(int i=0;i<arr.length;i++) {
			 if(arr[i].equals(courseNo)) continue;
			 s.append(arr[i]+",");
		 }
		 sc.setCourseNo(s);
		  int a = sc.getGrade();
		  a=a-(((Course)courseDao.getEntity(courseNo)).getCourseGrade());
		  sc.setGrade(a);
		  scDao.update1(sc);
		  save();
	  }
 }

  public static void showresult() throws FileNotFoundException{
	Scanner scan = new Scanner(System.in);
	System.out.println("请输入您本人的学号,以便于我们对您所选课程正选结果信息的查询:");
	String studentNo = scan.nextLine();
	SCDao scDao = SCDao.getInstance();
	SC sc = (SC)scDao.getEntity(studentNo);
	
	String[] courseNo = (sc.getCourseNo().toString()).split(",");
	System.out.println("您当前已选了如下课程,详细信息如下:");
	for(int i=0;i<courseNo.length;i++) {
		Course course = (Course)CourseDao.getInstance().getEntity(courseNo[i]);
		System.out.println("课程编号为"+course.getCourseNo()+",课程名称为"+course.getCourseName()+",课程学分为"+course.getCourseGrade());
	}
	
	System.out.println("以上便是您当前已选的所有课程的信息,综上,您当前已选了"+courseNo.length+"门课,总学分为"+sc.getGrade());
 }
}

StudentBiz.java

package biz;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;

import dao.StudentDao;
import entity.IEntity;
import entity.Student;
import view.MainUI;
public class StudentBiz {
	StudentDao studentDao;
	private Student student;
	//登录
	public void login(String studentNo, String studentPassword) throws IOException {

		studentDao = StudentDao.getInstance();
		student = (Student) studentDao.getEntity(studentNo);
		if (student == null) {
			System.out.println("用户不存在,请继续选择:");
			MainUI.main1();
		} else if (student.getStudentPassword().equals(studentPassword)) {
			System.out.println("登录成功,请根据您的需要在学生业务主菜单中进行选择:");
			MainUI.show();
		} else {
			System.out.println("密码不正确");
			MainUI.main1();
		}

	}
	public void save() throws IOException{
		StudentDao studentDao = StudentDao.getInstance();
		studentDao.update1();
	}
	//注册,业务逻辑实现
	public void register(String studentNo, 
						String studentName, 
						String studentGender, 
						int studentAge, 
						String studentDepartment, 
						String firstPassword, 
						String secondPassword) throws IOException {
		if(firstPassword.equals(secondPassword)) {
			student = new Student();
			student.setStudentNo(studentNo);
			student.setStudentName(studentName);
			student.setStudentGender(studentGender);
			student.setStudentAge(studentAge);
			student.setStudentDepartment(studentDepartment);
			student.setStudentPassword(firstPassword);
			
			studentDao = StudentDao.getInstance();
			
			studentDao.insert(student);
			int flag=0;
			while(true){
				if(flag==1) break;
				System.out.println("您已将您的个人信息完善成功,请您确认您的信息是否正确,不需改动请按1进行保存,需改动请按0进行修改:");
				Scanner scan = new Scanner(System.in);
				String option  = scan.nextLine();
				switch(option){
				case "1":flag=1; save(); System.out.println("恭喜您注册成功!请根据您的需要在学生业务主菜单中选择:");
			 MainUI.main1();  break;
				case "0":  MainUI.main1(); break;
				}
			}
			
		}else {
			System.out.println("您两次输入的密码不一致,请重新选择");
			MainUI.main1();
		}
	}
	
	public void modifyPassword(String studentNo,String oldPassword,String newPassword) throws IOException{
		StudentDao studentDao = StudentDao.getInstance();
		student = (Student) studentDao.getEntity(studentNo);
		if (student == null) {
			System.out.println("用户不存在,请继续选择:");
			MainUI.show();
		} else if (student.getStudentPassword().equals(oldPassword)) {
			student.setStudentPassword(newPassword);
			save();
			System.out.println("您已修改成功,请记住您当前修改的新密码,以便于您的下次登录!请在嘘声业务主菜单中继续选择:");
			MainUI.show();
		}else {
			System.out.println("您输入的旧密码错误,您没有权限进行修改,请重新选择:");
			MainUI.show();
		}
	}
	
}

dao包里的四个类:
CourseDao.java

package dao;
import java.util.*;
import java.io.*;
import entity.*;
public class CourseDao implements IDao {
	
	private static CourseDao instance;
	private HashMap<String, IEntity> courses= new HashMap<String, IEntity>();
	
	public CourseDao() {
	Course course1 = new Course();
	course1.setCourseNo("1");
	course1.setCourseName("概率论");
	course1.setCourseGrade(3);
	courses.put(course1.getCourseNo(),course1);
	
	Course course2 = new Course();
	course2.setCourseNo("2");
	course2.setCourseName("离散数学");
	course2.setCourseGrade(4);
	courses.put(course2.getCourseNo(),course2);
	
	Course course3 = new Course();
	course3.setCourseNo("3");
	course3.setCourseName("大学物理");
	course3.setCourseGrade(5);
	courses.put(course3.getCourseNo(),course3);
	
	Course course4 = new Course();
	course4.setCourseNo("4");
	course4.setCourseName("linux");
	course4.setCourseGrade(5);
	courses.put(course4.getCourseNo(),course4);
	}
	
	
	
	public static CourseDao getInstance() throws FileNotFoundException {
		if(instance == null) {
			synchronized(CourseDao.class) {
				if(instance == null) {
					instance = new CourseDao();
					return instance;
				}
			}
		}
		return instance;
	}
	
	
	@Override
	public void insert(IEntity entity) {
		// TODO Auto-generated method stub
		Course co = (Course)entity;
		courses.put(co.getCourseNo(), co);
//		update1();
	}

	@Override
	public void delete() {
		// TODO Auto-generated method stub
        
	}

	@Override
	public void update() {
		// TODO Auto-generated method stub

	}

	@Override
	public HashMap<String, entity.IEntity> getAllEntities() {
		// TODO Auto-generated method stub
		return courses;
	}

	@Override
	public IEntity getEntity(String Id) {
		// TODO Auto-generated method stub
		
		return courses.get(Id);
	}

}

IDao.java

package dao;
import java.util.HashMap;
import entity.IEntity;;

public interface IDao {
	void insert(IEntity ientity); //增加
	void delete();  //删除
	void update();  //修改
	public HashMap<String, IEntity> getAllEntities();  //获取全部实体
	public IEntity getEntity(String Id); //获取某个实体,即查询
}

SCDao.java

package dao;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import entity.*;
public class SCDao implements IDao {
	private static SCDao instance;
	private HashMap<String, IEntity> scs = new HashMap<String, IEntity>();
	
	private SC sc;
	
	//增加从文件读取的功能
			private SCDao() throws FileNotFoundException {
				getUsersFromInputStream("sc.txt");
			}
			
			public void processUserString(String userString) {

				String[] userFields = userString.split("/");
				SC u = new SC();
//				System.out.println(userFields.length+"***");
//				for(int i=0;i<userFields.length;i++){
//					System.out.println(userFields[i]);
//				}
//				System.out.println("*****");
				u.setStudentNo(userFields[0]);
				u.setGrade(Integer.parseInt(userFields[1]));
				StringBuffer s = new StringBuffer();
				s.append(userFields[2]);
				u.setCourseNo(s);
				scs.put(u.getStudentNo(), u);
				
//				u.s(userFields[0]);
//				u.setCardPwd(userFields[1]);
//				u.setUserName(userFields[2]);
//				u.setCall(userFields[3]);
//				u.setAccount(Integer.parseInt(userFields[4]));
//				users.put(u.getCardId(), u);

			}
	//
			//读取文件,以InputStream的形式读取
			private void getUsersFromInputStream(String isName) throws FileNotFoundException {

				FileInputStream fs = new FileInputStream(isName);
				byte[] content = new byte[1024];
				int i = 0;
				int conInteger = 0;
				while (true) {
					try {
						conInteger = fs.read();
					} catch (IOException e) {
						e.printStackTrace();
					}
					if (-1 == conInteger) {
						break;
					} else if ('\r' == (char) conInteger || '\n' == (char) conInteger) {
						try {
							this.processUserString(new String(content, "GBK").trim());
							i = 0;
						} catch (UnsupportedEncodingException e) {
							e.getStackTrace();
						}
						continue;
					} else {
						content[i] = (byte) conInteger;
						i++;
					}
				}
			}
//			
			
			// 存盘操作
			public void update1() throws IOException {
				Set<String> userSet = scs.keySet();
				StringBuffer uStringBuffer = new StringBuffer();
				for (String cardId : userSet) {
					SC u = (SC) scs.get(cardId);
					String uString =  u.getStudentNo() + "/" +u.getGrade() + "/" + u.getCourseNo()  
					+ "\r\n";
					
//					String uString =  "学生学号:"+u.getStudentNo() + "|" + "学生总学分:" +u.getGrade() + "|" +"学生所选的所有课程:"+ u.getCourseNo()  
//							+ "\r\n";
					uStringBuffer.append(uString);
				}
				putUserToFile(uStringBuffer.toString(), "sc.txt");
			}
			
			// 写入文件的函数
			private void putUserToFile(String uString, String osName) throws IOException {
				try {
					FileOutputStream fos = new FileOutputStream(osName);
					try {
						fos.write(uString.getBytes("GBK"));
					} catch (UnsupportedEncodingException e) {
						e.printStackTrace();
					}

				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}
			}
	
	public static SCDao getInstance() throws FileNotFoundException {
		if(instance == null) {
			synchronized(SCDao.class) {
				if(instance == null) {
					instance = new SCDao();
					return instance;
				}
			}
		}
		return instance;
	}
	
	@Override
	public void insert(IEntity ientity) {
		// TODO Auto-generated method stub
          scs.put(((SC)ientity).getStudentNo(),(SC)ientity);
          System.out.println("恭喜您已正选成功,请继续在选课主菜单中选择所要进行的操作:");
	}
	
	
	@Override
	public void delete() {
		// TODO Auto-generated method stub
		 
	}

	@Override
	public void update() {
		// TODO Auto-generated method stub
   
	}
	
	public void update1(IEntity ientity) {
		// TODO Auto-generated method stub
		scs.put(((SC)ientity).getStudentNo(),(SC)ientity);
        System.out.println("恭喜您已退选成功,请继续在选课主菜单中选择所要进行的操作:");
	}

	@Override
	public HashMap<String, IEntity> getAllEntities() {
		// TODO Auto-generated method stub
		return scs;
	}

	@Override
	public IEntity getEntity(String Id) {
		// TODO Auto-generated method stub
		return scs.get(Id);
	}

}

StudentDao.java

package dao;
import entity.IEntity;
import entity.Student;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Set;





public class StudentDao implements IDao {

	private static StudentDao instance;
	private HashMap<String, IEntity> students= new HashMap<String, IEntity>();
	private Student student= new Student();
	
	 //增加从文件读取的功能
		private StudentDao() throws FileNotFoundException {
			getUsersFromInputStream("student.txt");
		}
		
		public void processUserString(String userString) {

			String[] userFields = userString.split(",");
			Student u = new Student();
//			System.out.println(userFields.length+"***");
//			for(int i=0;i<userFields.length;i++){
//				System.out.println(userFields[i]);
//			}
//			System.out.println("*****");
			u.setStudentNo(userFields[0]);
			u.setStudentName(userFields[1]);
			u.setStudentGender(userFields[2]);
			u.setStudentAge(Integer.parseInt(userFields[3]));
			u.setStudentDepartment(userFields[4]);
			u.setStudentPassword(userFields[5]);
			students.put(u.getStudentNo(), u);
			
//			u.s(userFields[0]);
//			u.setCardPwd(userFields[1]);
//			u.setUserName(userFields[2]);
//			u.setCall(userFields[3]);
//			u.setAccount(Integer.parseInt(userFields[4]));
//			users.put(u.getCardId(), u);

		}
//
		//读取文件,以InputStream的形式读取
		private void getUsersFromInputStream(String isName) throws FileNotFoundException {

			FileInputStream fs = new FileInputStream(isName);
			byte[] content = new byte[1024];
			int i = 0;
			int conInteger = 0;
			while (true) {
				try {
					conInteger = fs.read();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (-1 == conInteger) {
					break;
				} else if ('\r' == (char) conInteger || '\n' == (char) conInteger) {
					try {
						this.processUserString(new String(content, "GBK").trim());
						i = 0;
					} catch (UnsupportedEncodingException e) {
						e.getStackTrace();
					}
					continue;
				} else {
					content[i] = (byte) conInteger;
					i++;
				}
			}
		}
//		
		
		// 存盘操作
		public void update1() throws IOException {
			Set<String> userSet = students.keySet();
			StringBuffer uStringBuffer = new StringBuffer();
			for (String cardId : userSet) {
				Student u = (Student) students.get(cardId);
//				System.out.println(u.getStudentNo()+"*****");
				String uString = u.getStudentNo() + "," + u.getStudentName() + "," + u.getStudentGender() + "," + u.getStudentAge() + ","
						+ u.getStudentDepartment() +","  + u.getStudentPassword()+ ","+"\r\n";
				uStringBuffer.append(uString);
			}
			putUserToFile(uStringBuffer.toString(), "student.txt");
		}
		
		// 写入文件的函数
		private void putUserToFile(String uString, String osName) throws IOException {
			try {
				FileOutputStream fos = new FileOutputStream(osName);
				try {
					fos.write(uString.getBytes("GBK"));
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}

			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
	
		
		
		public static StudentDao getInstance() throws FileNotFoundException {
			if (instance == null) {
				synchronized (StudentDao.class) {
					if (instance == null) {
						instance = new StudentDao();
					}
				}
			}
			return instance;
		}
//	public static StudentDao getInstance() {
//		if(instance == null) {
//			synchronized(StudentDao.class) {
//				if(instance == null) {
//					instance = new StudentDao();
//					return instance;
//				}
//			}
//		}
//		return instance;
//	}
	@Override
	public void insert(IEntity entity) {
		// TODO Auto-generated method stub
		Student st = (Student)entity;
		students.put(st.getStudentNo(), st);
		
	}

	@Override
	public void delete() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void update() {
		// TODO Auto-generated method stub

	}

	@Override
	public HashMap<String, IEntity> getAllEntities() {
		// TODO Auto-generated method stub
		return students;
	}

	@Override
	public IEntity getEntity(String Id) {
		// TODO Auto-generated method stub		
		return students.get(Id);
	}

}

**entity包里是4个类:

Course.java**

package entity;

public class Course implements IEntity {
	private String courseNo;
	private String courseName;
	private int courseGrade;
	public String getCourseNo() {
		return courseNo;
	}
	public void setCourseNo(String courseNo) {
		this.courseNo = courseNo;
	}
	public String getCourseName() {
		return courseName;
	}
	public void setCourseName(String courseName) {
		this.courseName = courseName;
	}
	public int getCourseGrade() {
		return courseGrade;
	}
	public void setCourseGrade(int courseGrade) {
		this.courseGrade = courseGrade;
	}
}

IEntity.java

package entity;

public interface IEntity {
	
}

SC.java

package entity;

public class SC implements IEntity {
	private String studentNo;
	private StringBuffer courseNo;
	private int grade;
	public String getStudentNo() {
		return studentNo;
	}
	public void setStudentNo(String studentNo) {
		this.studentNo = studentNo;
	}
	public StringBuffer getCourseNo() {
		return courseNo;
	}
	public void setCourseNo(StringBuffer courseNo) {
		this.courseNo=courseNo;
	}
	public int getGrade() {
		return grade;
	}
	public void setGrade(int grade) {
		this.grade = grade;
	}
}

Student.java

package entity;

public class Student implements IEntity {
	private String studentNo;
	private String studentName;
	private String studentGender;
	private int studentAge;
	private String studentDepartment;
	private String studentPassword;
	public String getStudentNo() {
		return studentNo;
	}
	public void setStudentNo(String studentNo) {
		this.studentNo = studentNo;
	}
	public String getStudentName() {
		return studentName;
	}
	public void setStudentName(String studentName) {
		this.studentName = studentName;
	}
	public String getStudentGender() {
		return studentGender;
	}
	public void setStudentGender(String studentGender) {
		this.studentGender = studentGender;
	}
	public int getStudentAge() {
		return studentAge;
	}
	public void setStudentAge(int studentAge) {
		this.studentAge = studentAge;
	}
	public String getStudentDepartment() {
		return studentDepartment;
	}
	public void setStudentDepartment(String studentDepartment) {
		this.studentDepartment = studentDepartment;
	}
	public String getStudentPassword() {
		return studentPassword;
	}
	public void setStudentPassword(String studentPassword) {
		this.studentPassword = studentPassword;
	}
}

view包里的5个类,其中MainUI为程序的入口:

CourseSelection.java

package view;
import java.util.*;

import biz.SCBiz;

import java.io.*;
public class CourseSelection {
	
//	private static final String String = null;

	//选课的主页
    public static void courseSelection() throws IOException{
    	Scanner scan = new Scanner(System.in);
    	int flag=0;
    	while(true) {
    		if(flag==1) break;
    	System.out.println("欢迎进入选课系统,请根据您的需要在选课主菜单中进行选择:");
    	System.out.println("************选课主菜单***********");
    	System.out.println("*                             *");
		System.out.println("*1-正选; 2-退选; 3-正选结果;4- 退出*");
		System.out.println("*                             *");
		System.out.println("*******************************");
		
		String option = scan.nextLine();
		SCBiz scBiz = new SCBiz();
		switch(option){
		case "1":
			scBiz.selection();
			break;
			
		case "2":
			scBiz.withdrawal();
			break;
			
		case "3":
			scBiz.showresult();
			break;
			
		case "4": flag=1;
		System.out.println("您已退出选课系统,请根据您的需要输入您所要进行的操作");
		MainUI.show();
			break;
		}
    	}
		
	}
}

LoginUI.java

package view;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;

import biz.StudentBiz;

public class LoginUI {	

	public static void show() throws IOException {
		Scanner scanner;
		String studentNo;
		String studentPassword;
		StudentBiz studentBiz;
		scanner = new Scanner(System.in);
		System.out.println("请输入学号:");
		studentNo = scanner.nextLine();
		System.out.println("请输入密码:");
		studentPassword = scanner.nextLine();
		
		studentBiz = new StudentBiz();
		studentBiz.login(studentNo, studentPassword);
	}
}

MainUI.java

package view;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
public class MainUI {
	public static void main(String[] args) throws IOException{
		Scanner scan = new Scanner(System.in);
		System.out.println("欢迎来到学生选课网站,请根据您的需要在网站主页中进行选择,我们将为您服务:");
		System.out.println("----------网站主页----------");
		System.out.println("|                         |");
		System.out.println("|1-登录;   2-注册;  3-退出;  |");
		System.out.println("|                         |");
		System.out.println("--------------------------");
		
		
		System.out.println("请输入您所选择的编号:");
		String a = scan.nextLine();
		switch(a){
		case "1":
			LoginUI.show(); 
			break;
		case "2":
			RegisterUI.show();
			break;
		case "3":
			break;
			}
	}
	
	public static void main1() throws IOException{
		Scanner scan = new Scanner(System.in);
		System.out.println("欢迎来到学生选课网站,请根据您的需要在网站主页中进行选择,我们将为您服务:");
		System.out.println("----------网站主页----------");
		System.out.println("|                         |");
		System.out.println("|1-登录;   2-注册;  3-退出;  |");
		System.out.println("|                         |");
		System.out.println("--------------------------");
		
		
		System.out.println("请输入您所选择的编号:");
		String a = scan.nextLine();
		switch(a){
		case "1":
			LoginUI.show(); 
			break;
		case "2":
			RegisterUI.show();
			break;
		case "3":
			System.out.println("您已退出该网站,感谢您的本次使用!");
			break;
			}
	}
	public static void show() throws IOException {
		System.out.println(" ———————————学生业务主菜单—————————————");
		System.out.println("|                                  |");
//		System.out.println("|1-注册;2-修改密码;3-选课;4-登录;0-退出  |");
		System.out.println("|      2-修改密码;  3-选课;                0-退出  |");
		System.out.println("|                                  |");
		System.out.println(" —————————————————————————————————— ");
		Scanner scanner = new Scanner(System.in);
		String option = scanner.nextLine();
		switch (option) {
//		case "1":
//			RegisterUI.show();
//			break;
		case "2":
			ModifyPasswordUI.show();
			break;
		case "3":
            CourseSelection.courseSelection();
			break;
//		case "4":  
//		     LoginUI.show();  
//		     break;
		case "0":
			System.out.println("欢迎您的本次使用,您已经成功退出您的账号,欢迎您的下次使用!");
			MainUI.main1();
			break;
		}
		
	}
}

ModifyPasswordUI.java

package view;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;

import biz.StudentBiz;

public class ModifyPasswordUI {
	public static void show() throws IOException {
         Scanner scan = new Scanner(System.in);
         String studentNo;
         String oldPassword;
         String newfirstPassword;
         String newsecondPassword;
         while(true){
        	 System.out.println("请输入您的学号,以便我们确认是您本人操作:");
         studentNo = scan.nextLine();
         System.out.println("请输入您的旧密码:");
         oldPassword = scan.nextLine();
         System.out.println("请输入您的新密码:");
         newfirstPassword = scan.nextLine();
         System.out.println("请再次输入您的新密码,我们需要再次确认:");
         newsecondPassword = scan.nextLine();
         if(newfirstPassword.equals(newsecondPassword)) {
        	 StudentBiz studentBiz = new StudentBiz();
         studentBiz.modifyPassword(studentNo,oldPassword,newfirstPassword); break;
         }
         else {
        	  System.out.println("您两次输入的新密码不一致,请重新输入:");
         }
         }
         
        
	}
}

RegisterUI.java

package view;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;

import biz.StudentBiz;
import dao.StudentDao;

public class RegisterUI {
	public static void show() throws IOException {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入学号:");
		String studentNo = scanner.nextLine();
		System.out.println("请输入姓名:");
		String studentName = scanner.nextLine();
		System.out.println("请输入性别:");
		String studentGender = scanner.nextLine();
		System.out.println("请输入年龄:");
		int studentAge = Integer.parseInt(scanner.nextLine());		
		System.out.println("请输入院系:");
		String studentDepartment = scanner.nextLine();
		System.out.println("请输入密码:");
		String firstPassword = scanner.nextLine();
		System.out.println("请再次输入密码:");
		String secondPassword = scanner.nextLine();
		
		StudentBiz sc = new StudentBiz();
		sc.register(studentNo, 
				studentName, 
				studentGender, 
				studentAge, 
				studentDepartment, 
				firstPassword, 
				secondPassword);
	}
}

还有两个.txt 文本文件用来动态存储学生选课的信息,及相当于一个数据库的作用,直接建即可,代码运行的过程中会自动写入相关信息。
在这里插入图片描述

评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值