길이가 사용자의 입력 인 객체 내에서 Array를 어떻게 초기화합니까? 나는 사용자 입력을 통해 박쥐 수를 설정하고 그 배열 길이를 basesAchieved
배열 내에서 만들고 싶습니다. 사용자 입력 (1-4)을 기준으로 숫자를 설정하고 기본을 나타냅니다. 당신이 this.basesAchieved = basesAchieved;
를 할당해야 setter
방법에서사용자 입력을 통한 자바 배열 길이 설정
// set up a Batter
public class Batter
{
private String batterName;
private int numberOfBats;
private int[] basesAchieved;
// fill fields with empty data, how is this done with an array??
public Batter()
{
this("", 0,0);
}
//
public Batter(String batterName, int numberOfBats, int[] basesAchieved)
{
this.batterName = batterName;
this.numberOfBats = numberOfBats;
this.basesAchieved = basesAchieved;
}
public void setBatterName(String batterName)
{
this.batterName = batterName;
}
public String getBatterName()
{
return batterName;
}
public void setNumberOfBats(int numberOfBats)
{
this.numberOfBats = numberOfBats;
}
public int getNumberOfBats()
{
return numberOfBats;
}
// want to set an array to get a number (1-4) for each number of @ bats
// (numberOfBats).
public void setBasesAchieved(int[] basesAchieved)
{
this.basesAchieved = ;
}
public int getBasesAchieved()
{
return basesAchieved;
}
}