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;

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

import 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;
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.

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY