Another question about my program that I am writing is called Flight. In my test, I create an object from the Flight class called myFlight. The object has several fields (the name of the flight, miles traveled, etc.), but what I'm doing is reading data from a file called input.txt and trying to put it in the object I created. There are five lines of information in the file I am reading. For some reason, I cannot get it right, if anyone can help me fix this problem, I would really appreciate it.
Here is a constructor that has all the fields from my Flight class:
public Flight(String name, int num, int miles, String origin, String destination)
{
Airlinename = name;
flightnumber = num;
numofmiles = miles;
Origincity = origin;
Destinationcity = destination;
}
And the part of my program where I created the object, and try to read the data from the file. I also created an empty constructor in my class, because I was not sure if I should put anything in the object when I created it.
Flight myFlight = new Flight();
File myFile = new File("input.txt");
Scanner inputFile = new Scanner(myFile);
while (inputFile.hasNext())
{
myFlight = inputFile.nextLine();
}
inputFile.close();
}
}
source
share