Can anyone tell me why I can’t create a new object in my Interactions panel or why this program won’t run even though it was compiled?
import java.util.Random;
/**
* This program allows a user to enter their first and last name
* and generate a random user id and default password.
*
* @author Brian Drake
* @version 9/14/11
*/
public class UserID {
private String firstName;
private String lastName;
private String userId;
private String password;
public UserID(String first, String last) {
Random generator = new Random();
firstName = first;
lastName = last;
userId = first.substring(0, 3) + last.substring(0, 3)
+ generator.nextInt(1) + (generator.nextInt(7) + 3)
+ generator.nextInt(10);
password = Integer.toString(generator.nextInt(10) + generator.nextInt(10)
+ generator.nextInt(10) + generator.nextInt(10)
+ generator.nextInt(10) + generator.nextInt(10));
}
public String getId() {
return userId;
}
public String getPassword() {
return password;
}
public boolean setPassword(String randomPass) {
if (password.length() < 6 || password.length() > 6) {
randomPass = password;
return false;
}
else {
password = randomPass;
}
return true;
}
public void generateNewPassword() {
Random generator = new Random();
password = Integer.toString(generator.nextInt(10) + generator.nextInt(10)
+ generator.nextInt(10) + generator.nextInt(10)
+ generator.nextInt(10) + generator.nextInt(10));
}
public String toString(String first, String last) {
String output = firstName + " " + lastName + "\n";
output += userId + "\n";
output += password;
return output;
}
}
In the class definition of
UserID, you need to assign parameter values while creating an object (because you didn’t create no argument constructor).Edit:
Apart from the
UserIDclass, you have to define another class which contains an entry point – main() method.