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

📄 user.java

📁 考试系统
💻 JAVA
字号:
package user;

/**
 * @author SpiritRain
 *
 * Abstract class of user set
 * provide access control
 * 
 */
public abstract class User {
	/**
	 * provide a default password
	 */
	private static char[] defaultpwd = new char[]{'0','0','0','0','0','0'};
	/**
	 * to indicate a student
	 */
	public static final int STUDENT = 0;
	/**
	 * to indicate a teacher
	 */
	public static final int TEACHER = 1;
	/**
	 * user name
	 */
	protected String name;
	/**
	 * password
	 */
	protected char[] pwd;

	/**
	 * create a new user whose user name is name,password is default password
	 * @param name user name
	 */
	public User(String name) {
		this(name, defaultpwd);
	}

	/**
	 * create a new user whose user name is name,password is pwd
	 * @param name user name
	 * @param pwd user's password
	 */
	public User(String name, char[] pwd) {
		this.name = name;
		this.pwd = pwd;
	}

	/**
	 * set user's password to new password<br />
	 * if old password equal to repeat password 
	 * @param oldPwd old password
	 * @param repeatPwd password that input again
	 * @param newPwd new password to be change to
	 */
	public void changePassword(
		char[] oldPwd,
		char[] repeatPwd,
		char[] newPwd) {
		if (this.checkPassword(oldPwd) && this.checkPassword(repeatPwd)) {
			this.pwd = newPwd;
		}
	}

	/**
	 * compare two password and check if it is equal 
	 * @param pwd password that user inputed
	 * @return true if pwd is equal to user's pwd,false otherwise
	 */
	public boolean checkPassword(char[] pwd) {
		if (this.pwd.length == pwd.length){
			for (int i = 0; i < pwd.length; i++){
				if (this.pwd[i] != pwd[i]){
					return false;
				}
			}
			return true;
		}
		return false;
	}

	/**
	 * get user name
	 * @return user name
	 */
	public String getName() {
		return this.name;
	}

	/**
	 * get user type teacher or student
	 * @return teacher value or student value
	 */
	public abstract int getPermission();
	
	/**
	 * @return sting of Teacher or Student
	 */
	public abstract String getPermissionString();

}

⌨️ 快捷键说明

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