Expand|Select|Wrap|Line Numbers
- public class Flight
- {
- private String orig,dest,day;
- private int depart, arrive;
- private double price;
- public Flight(String theOrig, String theDest, String theDay,
- int theDepart, int theArrive, double thePrice)
- {
- orig=theOrig;
- dest=theDest;
- day=theDay;
- depart=theDepart;
- arrive=theArrive;
- price=thePrice;
- }
- public String getOrig()
- {
- return orig;
- }
- public String getDest()
- {
- return dest;
- }
- public String getDay()
- {
- return day;
- }
- public int getDepart()
- {
- return depart;
- }
- public int getArrive()
- {
- return arrive;
- }
- public double getPrice()
- {
- return price;
- }
- public void setPrice(double thePrice)
- {
- price=thePrice;
- }
- public String toString()
- {
- return String.format ("%s %s %s %d %d %f",orig,dest,day,depart,arrive,price);
- }
- public static void main(String[] args)
- {
- Flight a= new Flight("DFW","JFK","MON",1000,1510,200.00);
- System.out.println(a.getOrig());
- System.out.println(a.getDest());
- System.out.println(a.getDay());
- System.out.println(a.getDepart());
- System.out.println(a.getArrive());
- a.setPrice(999.99);
- System.out.println(a.getPrice());
- System.out.println(a);
- }
- }
Expand|Select|Wrap|Line Numbers
- import java.io.*;
- import java.util.*;
- public class CheckFlights
- {
- public static void main (String[]args) throws FileNotFoundException
- {
- Flight[] a= new Flight[417];
- Scanner s= new Scanner(new FileReader("flights.txt"));
- String theOrig="";
- String theDest="";
- String theDay="";
- int theDepart=-1;
- int theArrive=-1;
- double thePrice=-1;
- for(int i=0; i< a.length && s.hasNextLine(); i++)
- {
- theOrig=s.next();
- theDest=s.next();
- theDay=s.next();
- theDepart=s.nextInt();
- theArrive=s.nextInt();
- thePrice=s.nextDouble();
- a[i]= new Flight(theOrig,theDest,theDay,theDepart,
- theArrive,thePrice);
- }
- for(int i=0;i<a.length &&a[i] != null;i++)
- {
- System.out.println(a[i]);
- }
- Scanner con= new Scanner (System.in);
- System.out.println("input origin that will be searched: ");
- String origToFind= con.next();
- System.out.println();
- System.out.println("input destination to search");
- String destToFind=con.next();
- System.out.println();
- String dayToFind=con.next();
- System.out.println("input day to search");
- }
- }
DFW JFK MON 1000 1510 200.00
DFW JFK MON 1400 1910 200.00
DFW JFK TUE 1000 1510 200.00
DFW JFK TUE 1400 1910 200.00
DFW JFK WED 1000 1510 200.00
DFW JFK WED 1400 1910 200.00
DFW JFK THU 1000 1510 200.00
<A massive amount of text has been removed, because it caused the message to disappear.
MODERATOR>
.....what i need my checkflights.java to do when it is run is to produce output that tells me the flight time and price from the txt file when i search for a specific flight....i believe this needs a while loop, can anyone help me