设计一个表示用户的User类,类中的变量有用户名、口令和记录用户个数的变量(静态的)定义类的3个构造方法(没有参数、有一个参数给用户赋值、有两个参数给用户名和口令赋值)、获取和设置口令的方法、返回字符串表示的类信息的方法(包括用户名、口令)。编写应用程序测试Use类
public class Use {
public static void main(String args[]){
User user1=new User();
user1.setUsername("joyce717533");
user1.setPassword("千总四级");
System.out.println("user1:"+user1.toString());
User user2=new User("joyce717533");
user2.setPassword("千总四级");
System.out.println("user2:"+user2.toString());
User user3=new User("joyce717533","千总四级");
System.out.println("user3:"+user3.toString());
}
}
class User {
public String username;
public String password;
public static int record;
public User() {
}
public User(String username){
this.username=username;
}
public User(String username,String password){
this.username=username;
this.password=password;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String toString(){
return "username: "+username+",passwrod: "+password;
}
}
已经给楼主写好了...祝楼主早日成功哈!!!!!
public static void main(String args[]){
User user1=new User();
user1.setUsername("joyce717533");
user1.setPassword("千总四级");
System.out.println("user1:"+user1.toString());
User user2=new User("joyce717533");
user2.setPassword("千总四级");
System.out.println("user2:"+user2.toString());
User user3=new User("joyce717533","千总四级");
System.out.println("user3:"+user3.toString());
}
}
class User {
public String username;
public String password;
public static int record;
public User() {
}
public User(String username){
this.username=username;
}
public User(String username,String password){
this.username=username;
this.password=password;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String toString(){
return "username: "+username+",passwrod: "+password;
}
}
已经给楼主写好了...祝楼主早日成功哈!!!!!
温馨提示:答案为网友推荐,仅供参考