我正在尝试访问我的程序不允许我访问的一些信息。在我的方法“addTrack”中,它无法识别 myTracklist 对象。如何使用主类中的方法调用 myTracklist.count?
public class CD {
String art;
String tit;
public CD(String artist, String title){
art = artist;
tit = title;
tracklist myTracklist = new tracklist(100);
}
public static void main(String[] args) {
String mainArtist;
String mainTitle;
CD myCD = new CD("Awesomeguy", "AwesomeCDName");
mainArtist = myCD.getArtist();
System.out.println(mainArtist);
mainTitle = myCD.getTitle();
System.out.println(mainTitle);
myCD.display();
}
public String getArtist(){
String person;
person = art;
return person;
}
public String getTitle(){
String name;
name = tit;
return name;
}
public boolean addTrack(String trackinfo){
boolean result = false;
if (myTracklist.count < 100){
myTracklist.add(trackinfo);
result = true;
}
return result;
}
public int numTracks(){
int amount;
amount = myTracklist.count();
return amount;
}
public void display(){
System.out.println("Artist = "+ art);
System.out.println("Title = "+ tit);
tracklist.display();
}
}
这是我的曲目列表课
public class tracklist {
int length;
int numUsed;
String[] storage;
public tracklist(int size){
length = size;
numUsed = 0;
storage = new String[length];
}
public int count(){
return numUsed;
}
}