public class FlightTest
{
public static void main(String[] args)
{
Flight info = new Flight(null, 0, null, null);
String name = "Delta Airlines";
int flightNum = 54663;
String origin = "Dallas, TX";
String destination = "Canton, MI";
info.setDestination(destination);
info.setFlightNum(flightNum);
info.setName(destination);
info.setOrigin(destination);
System.out.print(info);
}
}
上面的代码是我的驱动程序。
下面是我正在使用的方法。我不确定它是否没有被正确调用或没有被正确命名。
public class Flight {
private String name;
private int flightNum;
private String origin;
private String destination;
public Flight (String name, int flightNum, String origin, String destination) {
name = "";
flightNum = 0;
origin ="";
destination = "";
}
public enum Status {
ONTIME, DELAYED, CANCELLED;
}
private Status flightStatus = Status.ONTIME;
public String getName() {
return name;
}
public void setName(String newName) {
name = newName;
}
public int getFlightNum() {
return flightNum;
}
public void setFlightNum(int newFlightNum) {
flightNum = newFlightNum;
}
public String getOrigin() {
return origin;
}
public void setOrigin(String newOrigin) {
origin = newOrigin;
}
public String getDestination() {
return destination;
}
public void setDestination(String newDestination) {
destination = newDestination;
}
public String toString() {
return "The airline name is " +name+ ".\the flight number is " +flightNum+".\the origin is " + origin + ".\the destination is " +destination;
}
}
将.toString()被切断的话“中的”打印时,所有它打印出来是“密歇根州”以外flightnum的一切,这是正确的。
摇曳的蔷薇
子衿沉夜
相关分类