java - 如何修复 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());
}
}
解决方案
您需要将参数传递给 displayOutput 方法。尝试使函数返回特定对象,然后将其传递给 displayOutput。
推荐阅读
- javascript - 付费的 Chrome 扩展程序是否需要请求身份权限才能提供免费试用?
- c# - itext 7 - RTL 语言
- vmware-clarity - 带有垂直导航的树视图
- java - Java Streams API中的“forEach”是无序的原因是什么?
- angular - 如何为 Async Pipe 编写 jasmine 测试用例
- unit-testing - 用 mockk 一次只模拟一个电话
- python - 在内存范围查询中执行 geohash
- c++ - 为什么 malloc() 返回一个高地址?
- debugging - VS 2017 xamarin android项目中未命中断点
- css - CSS阴影真棒效果