rt java.util.Scanner; import java.io.File; import java.io.IOException; public class test2{ public static void main(String [] args)throws IOException{ File database = new File ("flights.txt"); Scanner fileReader = new Scanner( database ); Scanner input = new Scanner(System.in); // Displays the welcome screen int menuCheck = 0; String city = ""; float oneWayCost = 0f; float roundTripCost = 0f; int numberOfSeats = 0;
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
public class test2{
public static void main(String [] args)throws IOException{
File
Scanner fileReader = new Scanner( database );
Scanner input = new Scanner(System.in);
// Displays the welcome screen
int menuCheck = 0;
String city = "";
float oneWayCost = 0f;
float roundTripCost = 0f;
int numberOfSeats = 0;
float total = 0f;
while (menuCheck == 0){
System.out.println("Welcome TO MEjia AIRLINES.");
System.out.println("Please select a choice below [1-5]");
System.out.println(" 1. Add flight");
System.out.println(" 2. View trip");
System.out.println(" 3. Manage Trip");
System.out.println(" 4. Checkout");
System.out.println(" 5. Exit Mejia airlines");
int userInput = input.nextInt();
if (userInput == 5){
System.out.println("Thank You for using Mejia airlines");
System.out.println("Stay safe! Stay Hrydrated! Happy Coding!");
menuCheck = -5;
}else if (userInput == 1){
menuCheck = 1;
}else if (userInput == 2){
menuCheck = 2;
}else if (userInput == 3){
menuCheck = 3;
}else if (userInput == 4){
menuCheck = 4;
}
}while(menuCheck == 1){
System.out.format("+----------------------------------+%n");
System.out.format("| AVALABLE FLIGHTS FOR EP |%n");
System.out.format("+------------+---------+-----------+%n");
System.out.format("| CITY | ONE WAY | ROUND TRIP|%n");
System.out.format("+------------|---------|-----------+%n");
fileReader.nextLine();
while(fileReader.hasNextLine()){
city = fileReader.next();
oneWayCost = fileReader.nextFloat();
roundTripCost = fileReader.nextFloat();
System.out.printf("|%12s|$%3.2f|$%9.2f |\n," ,city,oneWayCost,roundTripCost);
System.out.format("+---------|---------|-----------+%n");
menuCheck = -1;
}
while(menuCheck == -1){
System.out.println("What City would you like to fly to?");
String userCity = input.nextLine();
File database2 = new File ("flights.txt");
Scanner fileReader2 = new Scanner (database2);
while (fileReader2.hasNextLine()){
city = fileReader2.next();
oneWayCost = fileReader2.nextFloat();
roundTripCost = fileReader2.nextFloat();
if(city.equals(userCity)){
System.out.println("What type of trip?");
System.out.println("1. One way");
System.out.println("2. Round trip");
int userTrip = input.nextInt();
}
}
}}while (menuCheck == 2){
System.out.println("View");
}while(menuCheck == 3){
System.out.println("Mange");
}while(menuCheck == 4){
System.out.println("total");
}
}
}
here's the Database
City OneWayCost RoundTripCost
Chicago 142.45 334.56
Dallas 150.3 375.2
Helsinki 678.33 1293.4
Memphis 104.45 389.4
Jeju 924.56 1839.56
Stokholm 836.78 1194.59
WashingtonDC 134.78 367.56
Tallin 945.09 1345.67
Cairo 770.12 1142.53
Copenhagen 883.45 1225.63
LosAngeles 234.56 376.56
Orlando 256.78 492.13
Tokyo 987.34 1450.34
Paris 873.12 1294.54
Shanghai 723.99 1156.10
London 929.22 1034.5
Huixtla 445.23 816.55
Cancun 539.45 869.34
Guadalajara 436.78 899.12
How do make it so when a user types in a name from a city from a file, it goes on to ask if they want to do a one way or round trip with different prices. And with type of trip it the user inputs, it well store the cost of the trip type. The user can add a infinite amount of flights.
Step by step
Solved in 2 steps