There is three file contains flight data. File data has in csv format.
1)Wright a standalone program to search flight detail from all files depend on criteria
2)Criteria would be departure location,arrival location, flight date.
3)Program should follow\Oops principle. And right unit test case also.
4)Result should be in Ascending or descending order.
5) data separated with pipe | .
File A has data like below:
FLIGHT_NUM|DEP_LOC|ARR_LOC|VALID_TILL|FLIGHT_TIME|FLIGHT_DURN|FARE
AF299|FRA|LHR|20-11-2010|0600|4.10|480
AF118|DUB|MUC|21-12-2010|1410|5.40|580
AF371|AMS|MAD|30-11-2010|1210|3.45|320
File B has data like below:
FLIGHT_NUM|DEP_LOC|ARR_LOC_VALID_TILL|FLIGHT_TIME|FLIGHT_DURN|FARE
BA123|DEL|AMS|12-10-2010|0050|8.00|950
BA412|BOS|CDG|31-12-2010|0210|7.50|800
BA413|BOS|AMS|30-11-2010|1530|7.00|750
File C has data like below:
FLIGHT_NUM|DEP_LOC|ARR_LOC_VALID_TILL|FLIGHT_TIME|FLIGHT_DURN|FARE
LH348|DEL|AMS|30-11-2010|2325|11.00|1050
LH201|LHR|MEL|21-11-2010|0230|15.30|1400
LH342|VIE|JFK|20-10-2010|1130|14.20|980
I have written here main business logic to search the required data from files and show to user.
package com.myapp.flightsearch.daoImpl;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;
import com.myapp.flightsearch.bean.FlightSearchDTO;
import com.myapp.flightsearch.dao.FlightSearchDAO;
import com.myapp.flightsearch.exception.FlightNotFoundException;
import com.myapp.flightsearch.utill.FlightComparator;
public class FlightSearchDAOImpl implements FlightSearchDAO {
@Override
public List<FlightSearchDTO> searchFlightPrepare(String dirLocation) throws FlightNotFoundException, FileNotFoundException {
File dir=new File(dirLocation);
List<FlightSearchDTO> flightDetailsInAllFiles=new ArrayList<FlightSearchDTO>();
if(dir.exists()){
File[] files = dir.listFiles();
for (int i = 0; i < files.length; i++) {
File file = files[i];
try {
BufferedReader readFileBr=new BufferedReader(new FileReader(file));
String fileData=null;
int firstLine=0;
while ((fileData = readFileBr.readLine()) != null) {
FlightSearchDTO flightSearchDTO=new FlightSearchDTO();
if(firstLine==0){
firstLine=1;
continue;
}
StringTokenizer st=new StringTokenizer(fileData,"|");
List<String> list = new LinkedList<String>();
int myIndex=0;
while(st.hasMoreElements()){
String data="";
data = (String)st.nextElement();
list.add(myIndex,data);
myIndex++;
}
flightSearchDTO.setFlightNumber(list.get(0));
flightSearchDTO.setDepartureLoccation(list.get(1));
flightSearchDTO.setArrivalLocation(list.get(2));
flightSearchDTO.setFlightDate(list.get(3));//valid till in csv file
flightSearchDTO.setFilghtTime(list.get(4));
flightSearchDTO.setFlightDuration(list.get(5));
flightSearchDTO.setFare(list.get(6));
flightDetailsInAllFiles.add(flightSearchDTO);
}
} catch (FileNotFoundException exception) {
new FlightNotFoundException(exception.getMessage());
}catch (IOException exception) {
new FlightNotFoundException(exception.getMessage());
}catch (Exception exception) {
new FlightNotFoundException(exception.getMessage());
}
}
return flightDetailsInAllFiles;
}else{
throw new FileNotFoundException("File is not found on given location");
}
}
@Override
public List<FlightSearchDTO> searchFlightResult(String depLoc,
String arrLoc, String flightDate, String outPref,String dirLocation)
throws FlightNotFoundException, FileNotFoundException {
List<FlightSearchDTO> allFlightData = searchFlightPrepare(dirLocation);
List<FlightSearchDTO> matchedFlightData=new ArrayList<FlightSearchDTO>();
for (Iterator iterator = allFlightData.iterator(); iterator.hasNext();) {
FlightSearchDTO flightSearchDTO = (FlightSearchDTO) iterator.next();
if(flightSearchDTO.getDepartureLoccation().equalsIgnoreCase(depLoc)&&flightSearchDTO.getArrivalLocation().equalsIgnoreCase(arrLoc)&&flightSearchDTO.getFlightDate().equalsIgnoreCase(flightDate)){
matchedFlightData.add(flightSearchDTO);
}
}
FlightComparator flightComparator = new FlightComparator();
flightComparator.setOutputPref(outPref);
Collections.sort(matchedFlightData, flightComparator);
return matchedFlightData;
}
}
1)Wright a standalone program to search flight detail from all files depend on criteria
2)Criteria would be departure location,arrival location, flight date.
3)Program should follow\Oops principle. And right unit test case also.
4)Result should be in Ascending or descending order.
5) data separated with pipe | .
File A has data like below:
FLIGHT_NUM|DEP_LOC|ARR_LOC|VALID_TILL|FLIGHT_TIME|FLIGHT_DURN|FARE
AF299|FRA|LHR|20-11-2010|0600|4.10|480
AF118|DUB|MUC|21-12-2010|1410|5.40|580
AF371|AMS|MAD|30-11-2010|1210|3.45|320
File B has data like below:
FLIGHT_NUM|DEP_LOC|ARR_LOC_VALID_TILL|FLIGHT_TIME|FLIGHT_DURN|FARE
BA123|DEL|AMS|12-10-2010|0050|8.00|950
BA412|BOS|CDG|31-12-2010|0210|7.50|800
BA413|BOS|AMS|30-11-2010|1530|7.00|750
File C has data like below:
FLIGHT_NUM|DEP_LOC|ARR_LOC_VALID_TILL|FLIGHT_TIME|FLIGHT_DURN|FARE
LH348|DEL|AMS|30-11-2010|2325|11.00|1050
LH201|LHR|MEL|21-11-2010|0230|15.30|1400
LH342|VIE|JFK|20-10-2010|1130|14.20|980
I have written here main business logic to search the required data from files and show to user.
package com.myapp.flightsearch.daoImpl;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;
import com.myapp.flightsearch.bean.FlightSearchDTO;
import com.myapp.flightsearch.dao.FlightSearchDAO;
import com.myapp.flightsearch.exception.FlightNotFoundException;
import com.myapp.flightsearch.utill.FlightComparator;
public class FlightSearchDAOImpl implements FlightSearchDAO {
@Override
public List<FlightSearchDTO> searchFlightPrepare(String dirLocation) throws FlightNotFoundException, FileNotFoundException {
File dir=new File(dirLocation);
List<FlightSearchDTO> flightDetailsInAllFiles=new ArrayList<FlightSearchDTO>();
if(dir.exists()){
File[] files = dir.listFiles();
for (int i = 0; i < files.length; i++) {
File file = files[i];
try {
BufferedReader readFileBr=new BufferedReader(new FileReader(file));
String fileData=null;
int firstLine=0;
while ((fileData = readFileBr.readLine()) != null) {
FlightSearchDTO flightSearchDTO=new FlightSearchDTO();
if(firstLine==0){
firstLine=1;
continue;
}
StringTokenizer st=new StringTokenizer(fileData,"|");
List<String> list = new LinkedList<String>();
int myIndex=0;
while(st.hasMoreElements()){
String data="";
data = (String)st.nextElement();
list.add(myIndex,data);
myIndex++;
}
flightSearchDTO.setFlightNumber(list.get(0));
flightSearchDTO.setDepartureLoccation(list.get(1));
flightSearchDTO.setArrivalLocation(list.get(2));
flightSearchDTO.setFlightDate(list.get(3));//valid till in csv file
flightSearchDTO.setFilghtTime(list.get(4));
flightSearchDTO.setFlightDuration(list.get(5));
flightSearchDTO.setFare(list.get(6));
flightDetailsInAllFiles.add(flightSearchDTO);
}
} catch (FileNotFoundException exception) {
new FlightNotFoundException(exception.getMessage());
}catch (IOException exception) {
new FlightNotFoundException(exception.getMessage());
}catch (Exception exception) {
new FlightNotFoundException(exception.getMessage());
}
}
return flightDetailsInAllFiles;
}else{
throw new FileNotFoundException("File is not found on given location");
}
}
@Override
public List<FlightSearchDTO> searchFlightResult(String depLoc,
String arrLoc, String flightDate, String outPref,String dirLocation)
throws FlightNotFoundException, FileNotFoundException {
List<FlightSearchDTO> allFlightData = searchFlightPrepare(dirLocation);
List<FlightSearchDTO> matchedFlightData=new ArrayList<FlightSearchDTO>();
for (Iterator iterator = allFlightData.iterator(); iterator.hasNext();) {
FlightSearchDTO flightSearchDTO = (FlightSearchDTO) iterator.next();
if(flightSearchDTO.getDepartureLoccation().equalsIgnoreCase(depLoc)&&flightSearchDTO.getArrivalLocation().equalsIgnoreCase(arrLoc)&&flightSearchDTO.getFlightDate().equalsIgnoreCase(flightDate)){
matchedFlightData.add(flightSearchDTO);
}
}
FlightComparator flightComparator = new FlightComparator();
flightComparator.setOutputPref(outPref);
Collections.sort(matchedFlightData, flightComparator);
return matchedFlightData;
}
}