Java 问题回顾法。不知道我哪里出错了
下面是我的代码,我在错误显示的旁边有注释。我不确定我在回忆我的方法时哪里出了问题,或者这是否是问题所在Java 问题回顾法。不知道我哪里出错了,java,methods,Java,Methods,下面是我的代码,我在错误显示的旁边有注释。我不确定我在回忆我的方法时哪里出了问题,或者这是否是问题所在 import java.util.Scanner; public class HurlerUse { static Hurler[] hurlerArray; // find lowest score (static method) public static int findLow(Hurler[] hurlerArray) {
import java.util.Scanner;
public class HurlerUse
{
static Hurler[] hurlerArray;
// find lowest score (static method)
public static int findLow(Hurler[] hurlerArray)
{
for(int i = 0; i < hurlerArray.length; i++)
{
int lowest = 0;
int index = 0;
for(int j=0; j<hurlerArray.length; j++)
{
int current = hurlerArray[i].totalPoints();// issue with my method 'totalPoints'
if(current < lowest)
{
lowest = current;
index = i;
}
}
return index;
}
}
//main code
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
Hurler[] hurlerArray = new Hurler[5];
for (int i = 0; i <4; i++)
{
hurlerArray[i] = new Hurler();
System.out.println ("Enter Hurler Name:");
hurlerArray[i].setName(sc.nextLine());
hurlerArray[i].setGoalsScored(sc.nextInt());
System.out.println("Enter the hurler's goals scored");
hurlerArray[i].setPointsScored(sc.nextInt());
System.out.println("Enter the hurler's points scored");
}
for(int i=0;i< hurlerArray.length; i++)
{
hurlerArray[i] = new Hurler(MyName, MyGoalsScored, MyPointsScored);// issue with all 3 objects in the brackets but im unsure of how to fix them
}
System.out.println("The lowest scoring hurler was " + hurlerArray[findLow(hurlerArray)].getName());// error with my code here I think it is in the method
}
}//end of class
}//下课
totalPoints()
有什么作用?你能发布它的代码吗?添加了相应的课程页面!这是一个需要解决的大问题吗?你认为呢?有几个问题。。。问题1:第二个“for”循环迭代“intj”值有什么原因吗?这可能是问题的一部分。问题2:“totalPoints”方法定义有两个参数(它甚至不使用)。在方法定义中去掉这两个参数。问题3:在你的主要方法中,在你刚刚定义了所有投掷者之后,你正在替换你的阵列中的所有投掷者。。。这是故意的吗?这实际上不应该与提供的代码一起工作,因为三个变量“MyName、MyGoalsScored、MyPointsScored”没有在任何地方定义。
public class Hurler
{
private String name;
private int goalsScored;
private int pointsScored;
public Hurler() //constructor default
{
name ="";
goalsScored = 0;
pointsScored = 0;
}
public Hurler(String myName, int myGoalsScored, int myPointsScored) // specific constructor
{
name = myName;
goalsScored = myGoalsScored;
pointsScored = myPointsScored;
}
//get and set name
public String getMyName()
{
return name;
}
public void setName(String myName)
{
name = myName;
}
//get and set goals scored
public int getGoalsScored()
{
return goalsScored;
}
public void setGoalsScored(int myGoalsScored)
{
goalsScored = myGoalsScored;
}
// get and set points scored
public int getPointsScored()
{
return pointsScored;
}
public void setPointsScored(int myPointsScored)
{
pointsScored = myPointsScored;
}
public int totalPoints(int myGoalsScored, int myPointsScored)
{
int oneGoal = 3;
int onePoint = 1;
int totalPoints = ((goalsScored * oneGoal) + (pointsScored * onePoint));
{
return totalPoints;
}
}