Java 方法';不要在Main中从另一个类运行

Java 方法';不要在Main中从另一个类运行,java,Java,我似乎不明白为什么我的第二个类“ZooAuthenticator”不能运行在第一个类“AuthenticatClass”中创建的其他方法。它似乎能够从authentiClass中的main方法运行main方法,但仅此而已。请帮帮我,我几乎完成了这个计划,我不明白为什么会发生这种情况 package zooauthenticator; import java.util.Scanner; import java.security.MessageDigest; import java.securit

我似乎不明白为什么我的第二个类“ZooAuthenticator”不能运行在第一个类“AuthenticatClass”中创建的其他方法。它似乎能够从authentiClass中的main方法运行main方法,但仅此而已。请帮帮我,我几乎完成了这个计划,我不明白为什么会发生这种情况

package zooauthenticator;

import java.util.Scanner;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.io.*;
import java.io.BufferedReader;
import java.io.IOException;

class authentiClass {



    public void sysStart1(){
        System.out.println("--System Startup Sequence Now Loading--");
    }
    public void sysStart2(){
        System.out.println(". . .");
    }
    public void sysStart3(){
        System.out.println("Loaded!");
    }
    public void sysStart4(){
        System.out.println();
        System.out.println();
        System.out.println("Welcome to the Central Zoo Keeping System!");
        System.out.println("Admins and Users can log in below.");
    }




    private String original;
    private String value;
    private String value2;
    private static String passwordToHash;
    private static String generatedPassword;
    public void authentiUser() throws java.io.IOException{
        System.out.println("Enter Active Username: ");

        BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
        value = bufferRead.readLine();
        System.out.println(value);

        System.out.println("Enter Active Password: ");

        value2 = bufferRead.readLine();
        System.out.println(value2);

        String adminPass = "letmein";
        String adminPass2 = "animal doctor";
        String vetPass = "secret password";
        String vetPass2 = "grizzly1234";
        String zooPass = "alphabet soup";
        String zooPass2 = "M0nk3y business";


        if (value2.equals(zooPass) || value2.equals(zooPass2)){
            System.out.println("Logged in!");
            System.out.println("Hello, Zookeeper!\n" +
            "\n" +
            "As zookeeper, you have access to all of the animals' information and their daily "
            + "monitoring logs. This allows you to track their feeding habits, habitat "
            + "conditions, and general welfare.");
            System.out.println("Press 0 to log out");
            Scanner choice = new Scanner(System.in);
            int c = choice.nextInt();

            if (c == 0){
            System.out.println("Logged out.");
            }
        }else{

        }


        if (value2.equals(vetPass) || value2.equals(vetPass2)){
            System.out.println("Logged in!");
            System.out.println("Hello, Veterinarian!\n" +
            "\n" + "As veterinarian, you have access to all of the animals' health records. "
            + "This allows you to view each animal's medical history and current "
            + "treatments/illnesses (if any), and to maintain a vaccination log.");
            System.out.println("Press 0 to log out");
            Scanner choice = new Scanner(System.in);
            int c = choice.nextInt();

            if (c == 0){
            System.out.println("Logged out.");
            }
        }else{

        }

        if (value2.equals(adminPass) || value2.equals(adminPass2)){
        System.out.println("Logged in!");
        System.out.println("Hello, System Admin!\n" +
        "\n" +
        "As administrator, you have access to the zoo's main computer system.");  
        System.out.println("This allows you to monitor users in the system and their roles.");
        System.out.println("Press 0 to log out");
        Scanner choice = new Scanner(System.in);
        int c = choice.nextInt();

        if (c == 0){
            System.out.println("Logged out.");
        }
        }else{

        }
    }

    public static void main(String[] args) throws NoSuchAlgorithmException 
    {
        passwordToHash = "password";
        generatedPassword = null;
        try {
            // Create MessageDigest instance for MD5
            MessageDigest md = MessageDigest.getInstance("MD5");
            //Add password bytes to digest
            md.update(passwordToHash.getBytes());
            //Get the hash's bytes 
            byte[] bytes = md.digest();
            //This bytes[] has bytes in decimal format;
            //Convert it to hexadecimal format
            StringBuilder sb = new StringBuilder();
            for(int i=0; i< bytes.length ;i++)
            {
                sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1));
            }
            //Get complete hashed password in hex format
            generatedPassword = sb.toString();
        } 
        catch (NoSuchAlgorithmException e) 
        {
            e.printStackTrace();
        }
        System.out.println(generatedPassword);
    }
}

class ZooAuthenticator {
    public void main (String[] args) throws NoSuchAlgorithmException, IOException{
        new authentiClass().sysStart1();
        new authentiClass().sysStart2();
        new authentiClass().sysStart3();
        new authentiClass().sysStart4();
        new authentiClass().authentiUser();
        new authentiClass().main(args);
}
}
包身份验证器;
导入java.util.Scanner;
导入java.security.MessageDigest;
导入java.security.NoSuchAlgorithmException;
导入java.io.*;
导入java.io.BufferedReader;
导入java.io.IOException;
类身份验证类{
public void sysStart1(){
System.out.println(“--系统启动序列正在加载--”);
}
公共无效sysStart2(){
System.out.println(“…”);
}
public void sysStart3(){
System.out.println(“已加载!”);
}
public void sysStart4(){
System.out.println();
System.out.println();
System.out.println(“欢迎来到中央动物园饲养系统!”);
System.out.println(“管理员和用户可以在下面登录”);
}
私人字符串原件;
私有字符串值;
私有字符串值2;
私有静态字符串passwordToHash;
私有静态字符串生成密码;
public void authentiUser()引发java.io.IOException{
System.out.println(“输入活动用户名:”);
BufferedReader bufferRead=新的BufferedReader(新的InputStreamReader(System.in));
value=bufferRead.readLine();
系统输出打印项次(值);
System.out.println(“输入活动密码:”);
value2=bufferRead.readLine();
系统输出打印项次(值2);
字符串adminPass=“letmein”;
字符串adminPass2=“动物医生”;
字符串vetPass=“秘密密码”;
字符串vetPass2=“grizzly234”;
字符串zooPass=“字母汤”;
字符串zooPass2=“M0nk3y业务”;
if(value2.equals(zooPass)| value2.equals(zooPass2)){
System.out.println(“登录!”);
System.out.println(“你好,动物园管理员!\n”+
“\n”+
“作为动物园管理员,您可以访问所有动物的信息及其日常信息”
+“监视日志。这允许您跟踪它们的食性、栖息地”
+“条件和一般福利。”);
System.out.println(“按0退出”);
扫描仪选择=新扫描仪(System.in);
int c=choice.nextInt();
如果(c==0){
System.out.println(“注销”);
}
}否则{
}
if(value2.equals(vetPass)| value2.equals(vetPass2)){
System.out.println(“登录!”);
System.out.println(“你好,兽医!\n”+
\n“+”作为兽医,您可以访问所有动物的健康记录
+“这允许您查看每只动物的病史和当前情况”
+“治疗/疾病(如有),并保存疫苗接种日志。”;
System.out.println(“按0退出”);
扫描仪选择=新扫描仪(System.in);
int c=choice.nextInt();
如果(c==0){
System.out.println(“注销”);
}
}否则{
}
if(value2.equals(adminPass)| value2.equals(adminPass2)){
System.out.println(“登录!”);
System.out.println(“你好,系统管理员!\n”+
“\n”+
“作为管理员,您可以访问动物园的主计算机系统。”);
println(“这允许您监视系统中的用户及其角色。”);
System.out.println(“按0退出”);
扫描仪选择=新扫描仪(System.in);
int c=choice.nextInt();
如果(c==0){
System.out.println(“注销”);
}
}否则{
}
}
公共静态void main(字符串[]args)抛出NoSuchAlgorithmException
{
passwordToHash=“password”;
generatedPassword=null;
试一试{
//为MD5创建MessageDigest实例
MessageDigest md=MessageDigest.getInstance(“MD5”);
//添加要摘要的密码字节
md.update(passwordToHash.getBytes());
//获取散列的字节数
byte[]bytes=md.digest();
//此字节[]具有十进制格式的字节;
//将其转换为十六进制格式
StringBuilder sb=新的StringBuilder();
for(int i=0;i
在ZooAuthenticator中,您的主方法应该是静态的。

尝试为该类创建一个对象,并使用该对象访问方法

authentiClass obj = new authentiClass();
obj.sysStart1();
obj.sysStart2();
obj.sysStart3();
obj.sysStart4();

当您运行“java类名”时,java会寻找一种特殊的格式来启动类 Java在给定的“Classname”中查找main方法,因为您在没有创建对象的情况下从外部调用,该方法应该是公共的和静态的。它总是在main方法中查找String[]参数数组

公共静态void main(字符串参数[]){

}

ZooAuthenticator缺少此格式