我无法更改在Main类中创建的对象的值。
它使用java jre8。我已经在Eclipse IDE上尝试过。
导入java.util.HashMap;
公共类主要{
public static HashMap<String,Data> PlayerData = new HashMap<String,Data>();
public static void main(String[] args) {
PlayerData.put("User1", new Data("User1","Password1",21));
PlayerData.get("User1").giveInformation();
PlayerData.get("User1").setAge(78);
try{
PlayerData.get("User1").giveInformation();
}catch(NullPointerException e) {
System.out.println("Error!");
}catch(Exception e) {
System.out.println("Error!");
}
}
}
类数据{
private String Name;
private String Password;
private int Age;
public Data(String Name, String Password, int Age) {
this.setName(Name);
this.setPassword(Password);
this.setAge(Age);
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getPassword() {
return Password;
}
public void setPassword(String password) {
Password = password;
}
public int getAge() {
return Age;
}
public void setAge(int age) {
Age = age;
}
public void giveInformation() {
System.out.println("Name: " + this.Name);
System.out.println("Password: " + this.Password);
System.out.println("Age: " + this.Age);
}
}
我想运行giveInformation()
方法来查看卡路里变化,但是我不知道该怎么做。