gpt4 book ai didi

java - 程序编译但无法运行,无法使用构造函数

转载 作者:行者123 更新时间:2023-12-01 16:37:41 26 4
gpt4 key购买 nike

谁能告诉我为什么我无法在“交互”面板中创建新对象,或者为什么该程序即使已编译也无法运行?

   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;
}

}

最佳答案

它不会运行,因为没有 main 方法

关于java - 程序编译但无法运行,无法使用构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7466379/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com