package Thirdweek;
import java.util.Scanner;
public class TestObject {
public static void main(String[] args) {
User u1=getUser();
User u2=getUser();
}
public static User getUser() {
System.out.println("请输入用户名:");
Scanner sc=new Scanner(System.in);
String username=sc.next();
System.out.println("请输入密码:");
String password=sc.next();
System.out.println("请输入电话号码:");
String tel=sc.next();
User u1=new User(username,password,tel);
return u1;
}
}
class User{
private String username;
private String password;
private String tel;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public User(String username) {
super();
this.username = username;
}
public User(String username, String password, String tel) {
this.username = username;
this.password=password;
this.tel=tel;
}
@Override
public String toString() {
username="一如既往";
password="123456";
tel="13051800688";
return "User [username=" + username + ", password=" + password + ", tel=" + tel + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((username == null) ? 0 : username.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
User other = (User) obj;
if (username == null) {
if (other.username != null)
return false;
} else if (!username.equals(other.username))
return false;
return true;
}
}