I am making a program which helps the user calculate the likely profitablilty of running a flight from UK airport to International airport. Uk airport can either be LPL or BOH.
Now, I want to read data from the csv text file and compare it with user input to check if the international airport the user wants matches same international airport in csv file. How do I do it.
Text file Contents
JFK,John F Kennedy International
ORY,Paris-Orly
MAD,Adolfo Suarez Madrid-Baranjas
AMS,Amsterdam Schipol
CAI,Cairo International
Code:
import java.io.IOException;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Scanner;
class Main {
// menu method
static void menu() {
System.out.println("------------------------------------------------------");
System.out.println("| Enter 1 to input airport details |");
System.out.println("| Enter 2 to input flight details |");
System.out.println("| Enter 3 to enter price plan and calculate profit |");
System.out.println("| Enter 4 to clear data |");
System.out.println("| Enter 5 to quit |");
System.out.println("------------------------------------------------------");
}
// text file
public static void main(String[] argv) throws Exception {
BufferedReader myFile = new BufferedReader(new FileReader("Airports.txt"));
ArrayList<String> listOfLines = new ArrayList<>();
String line = myFile.readLine();
while (line != null) {
listOfLines.add(line);
line = myFile.readLine();
}
myFile.close();
// main code
Scanner scanner = new Scanner(System.in);
System.out.println("\n" + "Welcome");
menu();
int menuChoice = scanner.nextInt();
if (menuChoice == 5) {
System.out.println("\n" + "You have selected quit");
System.out.println("Program ending.");
} else if (menuChoice == 1) {
System.out.println("\n" + "You have selected input airport details");
System.out.println("\n" + "Enter 3 letter airport code for UK airport");
String ukCode = scanner.next();
if (ukCode == "LPL" || ukCode == "BOH") {
//where I want to read csv text file and compare user input
}
}
}
}