【发布时间】:2016-02-17 15:45:20
【问题描述】:
我有这个问题有一段时间了,直到现在才设法避免它。基本上,我有一个类存储高尔夫球场每个洞的信息,并带有一个返回该信息的吸气剂。在另一个类中,当用户从洞 1 移动到洞 2(当前存储为整数)时,我希望访问洞 2 的 getter 方法,但无法弄清楚如何做到这一点。
代码:
课程信息类:
//Hole information
private static String[] hole1 = {"name", "Distance", "Par"};
private static String[] hole2 = {"name", "Distance", "Par"};
public static String[] getHole1(){
return hole1;
}
public static String[] getHole2(){
return hole2;
}
主类:
String[] holeInfo;
int currentHole = 1;
//How I call hole1 info just now
//I just access the elements of the array as needed then
holeCoOrds = course.getHole1();
//User starts next hole (this will be the case for all 18 holes)
currentHole++
//Call next hole information getter method here
//Something along the lines of;
holeCoOrds = course.getHole(currentHole)();
任何帮助将不胜感激,我已经绞尽脑汁一段时间了,但没有成功。
提前致谢。
【问题讨论】:
标签: java class dynamic-programming static-methods