Demo entry 6647072

User

   

Submitted by zsj on Oct 19, 2017 at 09:12
Language: Java. Code size: 755 Bytes.

/*
 * 类名:User
 * 成员变量:账号account,密码password,用户类别标志userType
 * 整形常量: VIP = 1, SIMPLE = 0
 * 成员方法:重写toString
 */
package library;

import java.util.ArrayList;

public class User {
	static final int VIP = 1;
	static final int SIMPLE = 0;
	
	static ArrayList<User> allUsers = new ArrayList<User>();
	
	String account;
	String password;
	int userType;
	
	//构造方法
	public User(String account, String password, int userType) {
		this.account = account;
		this.password = password;
		this.userType = userType;
		
		allUsers.add(this);
	}
	//无参数的构造方法
	public User() {
		
	}
	
	//重写toString
	public String toString() {
		String user_type = (userType == VIP)? "VIP: " : "Simple user: ";
		return user_type+" "+this.account;
	}
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).