I just wrote my second program to allow you to set and retrieve a username, password, and age for users.
public class Hello {
public User() {
}
public User(String username, String password, Int age) {
usrname = username;
usrpass = password;
usrage = age;
}
public void setUserName(String newusrname) {
usrname = newusrname;
}
public void setPassword(String newpass) {
usrpass = newpass;
}
public void setAge(Int newage) {
usrage = newage;
}
public String getUserName() {
return usrname;
}
public String getPassword() {
return usrpass;
}
public Int getAge() {
return usrage;
}
public static void main(String args[]) {
usr1 = new User();
usr1.setUserName("UserOne");
usr1.setPassword("PasswordOne");
usr1.setAge(1);
usr2 = new User("UserTwo", "PasswordTwo", 2);
System.out.println("User 1: " + usr1.getUserName + " " + usr1.getPassword + " " +usr1.getAge);
System.out.println("\n");
System.out.println("User 2: " + usr2.getUserName + " " + usr2.getPassword + " " +usr2.getAge);
}
}
...And here's the errors I get when I compile it...
Code:
C:\j2sdk1.4.2_11\bin>javac Hello.java
Hello.java:2: invalid method declaration; return type required
public User() {
^
Hello.java:4: invalid method declaration; return type required
public User(String username, String password, Int age) {
^
2 errors
...I'm pretty sure I understand what these errors mean (return type would be like public String getPassword(), right?), but I just want these ... definitions (I dont know the word yet, new to the vocabulary) of User() to just be used for constructors...I don't want them to return anything.
Thanks