首页 > 解决方案 > 如何修复 Main 类型中的方法不适用于参数 ()

问题描述

所以这是我的代码,我试图找出一种方法来摆脱这个错误:

Main 类型中的方法 displayOutput(inputPlayerName, inputStrength, inputAgility, inputIntelligence) 不适用于 arguments ()

我尝试过尝试,但仍然没有运气。

public static void main(String[] args) {
        inputPlayerName();
        inputStrength();
        inputAgility();
        inputIntelligence();
        displayOutput();
    }

    static void inputPlayerName() {
        inputPlayerName iPN = new inputPlayerName();
        Scanner sc = new Scanner(System.in);
        System.out.print("Name of the Adventurer: " );
        iPN.setName(sc.nextLine()); 
        System.out.println("Welcome! " + iPN.getName());        
    }
    
    static void inputStrength() {
        Scanner scan = new Scanner(System.in);
        inputStrength iS = new inputStrength();
        
        System.out.println("Set your 'Strength' attribute. Maximum of 5 points each. You have  15 points left ");
        iS.setStr(scan.nextInt());
        System.out.println(" Strength :" + iS.getStr());
        
        while (iS.getStr() > 5) {
            System.out.println(" Maximum is 5. Please enter value (1-5) ");
            System.out.println("");
            System.out.println("Set your 'Strength' attribute. Maximum of 5 points each. You have  15 points left ");
            iS.setStr(scan.nextInt());
            System.out.println(" Strength : " + iS.getStr());
        }
    }
    
    static void inputAgility() {
        Scanner scan1 = new Scanner(System.in);
            inputAgility iA = new inputAgility();
            
            System.out.println(" Set your 'Agility' attribute. Maximum of 5 points each. You have  15 points left ");
            iA.setStr(scan1.nextInt());
            System.out.println(" Agility :" + iA.getAgi());
            
            while (iA.getAgi() > 5) {
                System.out.println("Maximum is 5. Please enter value (1-5 ");
                System.out.println("");
                System.out.println("Set your 'Agility' attribute. Maximum of 5 points each. You have  15 points left ");
                iA.setStr(scan1.nextInt());
                System.out.println(" Agility : " + iA.getAgi());
            }
     }
     
    static void inputIntelligence() {
        Scanner scan2 = new Scanner(System.in);
        inputIntelligence iI = new inputIntelligence();

        System.out.println("Set your 'Intelligence' attribute. Maximum of 5 points each. You have  15 points left ");
        iI.setInt(scan2.nextInt());
        System.out.println(" Intelligence :" + iI.getInt());

        while (iI.getInt() > 5) {
            System.out.println("Text color: Red Maximum is 5. Please enter value (1-5 ");
            System.out.println("");
            System.out.println("Set your 'Strength' attribute. Maximum of 5 points each. You have  15 points left ");
            iI.setInt(scan2.nextInt());
            System.out.println(" Intelligence : " + iI.getInt());
        }
    }
     
    private static void displayOutput (inputPlayerName iPN, inputStrength iS,inputAgility iA,inputIntelligence iI) {
        System.out.println("_____________________________________________________________________");
        System.out.println("Congratulations! You have created a new Adventurer");

        System.out.println("Adventurer name : " + iPN.getName());
        System.out.println("Strength : " + iS.getStr());
        System.out.println("Agility : " + iA.getAgi());
        System.out.println("Intelligence : " + iI.getInt());
    }    
}

标签: java

解决方案


您需要将参数传递给 displayOutput 方法。尝试使函数返回特定对象,然后将其传递给 displayOutput。


推荐阅读