我正在构建一个模拟潜水比赛的程序。我有一个Athlete
基本上试图访问另一个类中的数组元素的类。有人知道我如何访问数据吗?
这是Athlete
课程:
public class Athlete {
public static String[] name = { "Art Class", "Dan Druff", "Jen Tull" };
public static String[] country = { "Canada", "Germany", "USA" };
Performance[] performance = new Performance[2];
public Athlete(String[] name, String[] country) {
this.name = name;
this.country = country;
// this.event = event;
}
public void perform() {
Dive mydive = new Dive(Dive.diveName, Dive.difficulty);
Performance event = new Performance(event.dive, Performance.judgeScores);
performance[0] = event(event.dive.diveNames[0], event.judgeScores); // here
performance[1] = event; // Here
performance[2] = event; // Here
}
public void printResults() {
}
}
用“//Here”指示的地方我试图从下面显示的类中访问数据,我想知道我该怎么做?
表现:
public class Performance {
Dive dive = new Dive(Dive.diveName, Dive.difficulty);
public static float[] judgeScores = new float[7];
public Performance(Dive dive, float[] judgeScores) {
this.dive = dive;
// this.dive=difficulty;
this.judgeScores = judgeScores;
// this.judgeScores = judgeScores;
}
}
潜水:
import java.util.Random;
public class Dive {
public static String diveName;
public static int difficulty;
public static final String[] diveNames = { "reverse pike", "forward pike",
"reverse armstand with double somersault", "reverse triple twist",
"double forward with triple somersault", "cannon ball" };
public static final int[] diveDifficulties = { 3, 2, 2, 4, 4, 1 };
public static Dive chosenRandomly() {
Random rand = new Random();
int num = rand.nextInt(6) + 1;
String diveName = diveNames[num];
int difficulty = diveDifficulties[num];
Dive dive = new Dive(diveName, difficulty);
return dive;
}
public Dive(String diveName, int difficulty) {
this.diveName = diveName;
this.difficulty = difficulty;
}
}
我的构造函数都错了吗?
PS:这是作业,所以有些人可能不认为我的方法是解决问题的合适方法,但请记住我正在按照说明进行操作。
提前感谢您的任何意见!