In this project, you will implement an airport system. In this system, we keep the flight details in a file. Please see
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
In this project, you will implement an airport system. In this system, we keep the flight details in a file. Please see
In this project, you will implement an airport system. In this system, we keep the flight details in a file. Please see image 1 for our input file. In this file, there are 9 Flights whose origin is our airport. In each line, you see the destination code, flight time, filight code (airline and flight code actually but consider them combined), eco price, flex price and business price. E. JFK 16.20 TROOI 1200 1800 5700 means there is a flight from our airport which will go to JFK airport at 16.20 with flight code TK001. Prices for eco, flex and business seats are 1200, 1800 and 5700 dollars. in.txt JIK 16.28 TL 1.201 332 ST LAK 35.28 V1458 2328 EST 1.28 KLH12 228 4800 ACA 2.38 AAS 6731 310 AOC 11.9 DL11 318 548 se 4.90 RON 1200 CD 34.40 R3401 LAK 23.02 ACC 3.38 112 318 348 34 Image 1 -input file: Intat STEP 1 - Create a Flight class. In this class, you will: declare 4 private variables: destination: String o time: String code: String Cost: int[] . methods as o 2 constructors . no-arg • all strings to empty string . initialize cost array to have 3 elements (for eco, flex and business) arguments as: String, String, String, int, int, int • all strings to empty string • Initialize cost array to have 3 elements • all costs Initialized with given arguments 1 set method (String String, String, int, int, Int) to setup all variables all setters and getters of instance variables STEP 2 -Create a file similar to above (you can use the same). STEP 3 -- Now.create a driver dass for testing purposes. This class has a main method and a . a a method: int returnArrayIndex(String code) In the main method • Create a Flight array of number of items in your text file for the given example, it is 9) . Create an integer array of the same number of items to keep reservations. This array will increment the number of reservations for chosen flight. Read d the file. AS YOU READ YOUR FILE, YOU HAVE TO HANDLE EXCEPTIONS IN A TRY_CATCH BLOCK BY USING FileNotFoundException How to read a file (this example is without exceptions but you need to add exceptions, too! File Eyobj - w File("in.txt"); Scanner wykeader - Scanner wyb> while (ry Reader, has extLine()) String data - myReader.nextLine(); 1 Do anything you need ) syReader.close(): You are free to use any method to read your file. You can read char by char, word by word or line by line. The above example reads the line, so the programmer needs to split It to destination, time, code and costs. Initialize your Flight objects in the array with the read information Show Options to the user and ask what they want: 11 See all rights ! Make a reservation 3: Airport based flights • Buit if 1 - show all nights if 2 - ask the code. Find the index of this code in the reservations array by using a helper method (returnArrayIndex) returnArrayIndex method returns the array index of any given flight code, eg "TK001" → 0; "VR65 → 1; "KLM12"► 2; etc. Increment the value of the given code in the reservations array. Print it • If 3, show airport based flights. hace If 4, exit. . For all cases, see the below sample output and be consistent with it Press: 1: See all flights 2: Make a reservation 3: Airport based flights @ @: Exit 1 Flight Details for Flight 1 Destination is: JFK Tine is: 16.20 Code is: TK81 Eco price is: 1200 Flex price is: 1808 Business price is: 5788 Flight Details for Flight 2 Destination is: LAX Tine is: 18.20 Code is: VR65 Eco price is: 450 Flex price is: 658 Business price is: 2308 Flight Details for Fught Destination ist IST Tine is: 1.20 Code is: KLM12 Eco price is: 1008 Flex price is: 2006 Business price is: 4080 Flight Details for Flight 4 Destination is: ACA Tine is: 2.38 Code is: AA23 Eco price is: 668 Flex price is: 788 Business price is: 1188 Flight Details for Flight 5 Destination is: ACC Tine is: 11.30 Code is: DL11 Eco price is: 310 Flex price is: 540 Business price is: 908 Flight Details for Flight 6 Destination is: NW Tine is: 4.5a Code is: KLM24 Eco price is: 450 Flex price is: 678 Business price is: 1200
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!