好的,我正在创建一个simple
航班预订系统。我花了相当多的时间进行调试,现在即使是最简单的事情也让我感到难过。
我的界面看起来很接近:
public class Flight implements IFlight {
String destination;
String departure;
int clubrows = 0;
int ecorows = 0;
public Flight(String dest, String dept, int clubrow, int ecorow) {
destination = dest;
departure = dept;
clubrows = clubrow;
ecorows = ecorow;
}
public String getDestination() {
return destination;
}
这个类有许多类似的get方法。 现在我正在尝试编写一个for循环,其中输出的每个值都打印出来。所以我需要访问所有0值然后所有1个值等。 它现在看起来有点像这样:
public void flightManifest() {
System.out.println("Available flights: ");
for(int i=0; i<flightCount ;i++){
System.out.println("Flight number: "+flightCount +", Destination: "+ +", Departure time: "+ );
}
因此,基本上每当我尝试访问变量时,我都会继续对其进行处理,那么我每次都想要访问这些值?
所以我存储它们的方式是这样的: flightArr [flightCount] = new Flight(dest,dept,clubrow,ecorow); flightCount ++; 或者至少是如何制作的。
答案 0 :(得分:1)
为toString()
课程提供Flight
方法,然后在循环中调用它。
在该toString()
方法中,返回类字段的字符串连接。就是这样。