我想在我的运动员类中打印国家和姓名两个数组的第一个元素。我还需要创建一个对象来模拟运动员进行的三次跳水尝试(最初设置为零)。我对面向对象编程很陌生,不知道如何在我的主函数中处理这个问题...至于构造函数方面,这是我目前所做的:
这是主要代码:
import java.util.Random;
import java.util.List;
public class Assignment1 {
public static void main(String[] args) {
Athlete art = new Athlete(name[0], country[0], performance[0]);
}
}
我真的不确定该怎么做...
这是包含数组的类。
import java.util.Random;
import java.util.List;
public class Athlete {
public String[] name = {"Art", "Dan", "Jen"};
public String[] country = {"Canada", "Germant", "USA"};
//Here i would like to create something that would be representing 3 dive attemps (that relate to dive and score. eventually.)
Athlete(String[] name, String[] country, Performance[] performance) {
this.name = name;
this.country=country;
this.performance=performance;
}
public Performance Perform(Dive dive){
dive.getDiveName();
return null;
}
public String[] getName() {
return name;
}
public void setName(String[] name) {
this.name = name;
}
public String[] getCountry() {
return country;
}
public void setCountry(String[] country) {
this.country = country;
}
}
感谢您提前的帮助和贡献!顺便说一下,还有其他类别,但目前不相关...