Question

This is in Java The Problem: A common task in computing is to take data and...

This is in Java

The Problem:

A common task in computing is to take data and apply changes (called transactions) to the data, then saving the updated data. This is the type of program you will write.

            You will read a file of flight reservation data to be loaded into an array with a max size of 20. A second file will hold the transactions that will be applied to the data that has been stored in the array. At the end of the program, the updated data in the array will be written to a third file.

Flight class

This class will hold the information about a flight. It is responsible for the following data: flight number, flight date, departure airport, arrival airport, departure time, arrival time, and seat assignment. The date will be in the form mm/dd/yyyy. The time will be in the form hh:mm PM. This class should include a default constructor and another constructor that will receive data for all of the instance variables. Also include toString and equals methods. The toString needs to format the data in the form that is needed for output written to the screen in an itinerary. Two Flight classes are considered equal when they have the same flightNumber and flightDate.

Reservation class

This class holds all of the information about a reservation for one person. It will include the passenger’s name (one variable to hold first and last names), reservation number, departure flight and return flight (the flights are objects of the Flight class). Constructors should include a default constructor and another one that accepts values for all of the instance variables. Also include toString and equals methods. The toString needs to format the data in the format of output written to the screen in an itinerary. Reservations are considered to be equal when they have the same reservation number.

Airline class

This class is responsible for holding the array of reservations and all of the methods to process the transactions. Transactions are represented in the file with a numeric code as follows:

Code

Transaction

1

Add a reservation – all data will be the same format as the reservations that are loaded into the array at the beginning of the program.

2

Print the itinerary of one passenger – Printed to the screen

3

Print the itineraries of all of the reservations – Printed to the screen

4

Write list to file – Writes all of the updated reservations in the list to a file

AirlineInput class

There are two input files. The first file, AirlineData.txt, holds all of the existing reservations. This should be read at the beginning of the program and stored in an array. The second file, Transactions.txt, has the transaction codes and data that is associated with each code.

AirlineData.txt format

Transactions.txt format.

Note: each type of transaction requires different input. The code will be followed by the data required for that code. There will be a code and data in one of the following formats.

Transaction code 1

< reservation number>

Transaction code 2

Transaction code 3

Transaction code 4

AirlineOutput class

This class will be responsible for:

Code 2 – Displaying the itinerary for one passenger

Sample output:

Passenger Name: Carl Foreman

Reservation Number: 1234

DepartureFlight:

Flight Number: UA1235

Flight Date: June 23, 2014

Departure Airport: null

Arrival Airport: null

Departure Time: 4:00 PM

Arrival Time: 7:15 PM

Seat: 23A

Return Flight:

Flight Number: UA673

Flight Date: July 12, 2014

Departure Airport: null

Arrival Airport: null

Departure Time: 10:00 AM

Arrival Time: 11:25 AM

Seat: 8A

Note that the date has been changed from the form 04/16/2014 to the form April 16, 2014

Code 3 – Displaying the itineraries for all reservations

This displays the itinerary for each person in the same format as above.

Leave a blank line between each itinerary.

Code 4 – Writing the contents of the array to the fileThis should be in the same format as the input file AirlineData.txt

The data can be left in the format used to display to the screen.

Name this file xxx-UpdatedData.txt where the xxx represents your initials.

AirlineData.txt

Carl Foreman
1234
UA1235
06/23/2014
ORD
LGA
4:00 PM
7:15 PM
23A
UA673
07/12/2014
LGA
ORD
10:00 AM
11:25 AM
8A
Jennifer Foreman
1235
UA1235
06/23/2014
ORD
LGA
4:00 PM
7:15 PM
23B
UA673
07/12/2014
LGA
ORD
10:00 AM
11:25 AM
8B
Jane Anderson
4577
UA317
08/04/2014
ORD
SFO
8:10 AM
10:45 AM
11C
UA728
08/14/2014
SFO
ORD
12:52 PM
7:03 PM
10D
Jason Anderson
4578
UA317
08/04/2014
ORD
SFO
8:10 AM
10:45 AM
11D
UA728
08/14/2014
SFO
ORD
12:52 PM
7:03 PM
10C
Kimberly Jones
8975
UA605
04/20/2014
ORD
DEN
10:00 AM
11:39 AM
25D
UA830
4/29/2014
DEN
ORD
3:39 PM
7:08 PM
30C
Doug Jones
8976
UA605
04/20/2014
ORD
DEN
10:00 AM
11:39 AM
25E
UA830
04/29/2014
DEN
ORD
3:39 PM
7:08 PM
30D

Transactions.txt

1
John Miller
1234
UA1235
06/12/2014
ORD
LGA
4:00 PM
7:15 PM
30F
UA673
06/19/2014
LGA
ORD
10:00 AM
11:25 AM
10E
3
1
Bob Barker
8497
UA317
08/04/2014
ORD
SFO
8:10 AM
10:45 AM
12A
UA728
08/14/2014
SFO
ORD
12:52 PM
7:03 PM
18A
2
1235
2
8976
3
4
0 0
Add a comment Improve this question Transcribed image text
Answer #1

package edu.ilstu;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Route {

public final static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("mm/dd/yyyy");

private int routeNumber;

private Date routeDate;

private String departureTrack;

private String arrivalTrack;

private String arrivalTime;

private String departureTime;

private String seat;

public Route() {

}

public Route(int routeNumber, Date routeDate, String departureTrack, String arrivalTrack, String arrivalTime,

String departureTime, String seat) {

this.routeNumber = routeNumber;

this.departureTrack = departureTrack;

this.arrivalTrack = arrivalTrack;

this.arrivalTime = arrivalTime;

this.departureTime = departureTime;

this.seat = seat;

}

public int getRouteNumber() {

return routeNumber;

}

public void setRouteNumber(int routeNumber) {

this.routeNumber = routeNumber;

}

public Date getRouteDate() {

return routeDate;

}public void setRouteDate(Date routeDate) {

this.routeDate = routeDate;

}

public String getDepartureTrack() {

return departureTrack;

}

public void setDepartureTrack(String departureTrack) {

this.departureTrack = departureTrack;

}

public String getArrivalTrack() {

return arrivalTrack;

}

public void setArrivalTrack(String arrivalTrack) {

this.arrivalTrack = arrivalTrack;

}

public String getArrivalTime() {

return arrivalTime;

}

public void setArrivalTime(String arrivalTime) {

this.arrivalTime = arrivalTime;

}

public String getDepartureTime() {

return departureTime;

}

public void setDepartureTime(String departureTime) {

this.departureTime = departureTime;

}

public String getSeat() {

return seat;

}

public void setSeat(String seat) {

this.seat = seat;

}

@Override

public String toString() {

return "Route Number=" + routeNumber + ", route Date=" + DATE_FORMAT.format(routeDate) + "\n departureTrack:-\n"+ departureTrack + "\narrivalTrack:- \n" + arrivalTrack + ", arrivalTime=" + arrivalTime+ ", departureTime=" + departureTime + ", seat=" + seat;

}

@Override

public int hashCode() {

final int prime = 31;

int result = 1;

result = prime * result + ((routeDate == null) ? 0 : routeDate.hashCode());

result = prime * result + routeNumber;

return result;

}

@Override

public boolean equals(Object obj) {

if (this == obj)

return true;

}

@Override

public boolean equals(Object obj) {

if (this == obj)

return true;

if (obj == null)

return false;

if (getClass() != obj.getClass())

return false;

Route other = (Route) obj;

if (routeDate == null) {

if (other.routeDate != null)

return false;

} else if (!routeDate.equals(other.routeDate))

return false;

if (routeNumber != other.routeNumber)

return false;

return true;

}

}

package edu.ilstu;

public class Reservation {

private String passengerName;

private String reservationNumber;

private Route departureRoute;

private Route returnRoute;

public Reservation() {

}

public Reservation(String name, String reservationNumber, Route departure, Route returnRoute) {

this.passengerName = name;

this.reservationNumber = reservationNumber;

this.departureRoute = departure;

this.returnRoute = returnRoute;

}

public String getPassengerName() {

return passengerName;

}

public void setPassengerName(String passengerName) {this.passengerName = passengerName

}

public String getReservationNumber() {

return reservationNumber;

this.passengerName = passengerName;

}

public String getReservationNumber() {return reservationNumber;}public void setReservationNumber(String reservationNumber) {this.reservationNumber = reservationNumber;}public Route getDepartureRoute() {

return departureRoute;

}

public void setDepartureRoute(Route departureRoute) {

this.departureRoute = departureRoute;

}

public Route getReturnRoute() {

return returnRoute;

}

public void setReturnRoute(Route returnRoute) {

this.returnRoute = returnRoute;

}

@Override

public String toString() {

return "Passenger Name=" + passengerName + ", Reservation Number=" + reservationNumber + ", Departure route="+ departureRoute + ", Return route=" + returnRoute;

}

@Override

public int hashCode() {

public int hashCode() {

final int prime = 31;

int result = 1;

result = prime * result + ((reservationNumber == null) ? 0 : reservationNumber.hashCode());

return result;

}

@Override

public boolean equals(Object obj) {

if (this == obj)

return true;

if (obj == null)

return false;

if (getClass() != obj.getClass())

return false;

Reservation other = (Reservation) obj;

if (reservationNumber == null) {

if (other.reservationNumber != null)

return false;

} else if (!reservationNumber.equals(other.reservationNumber))

return false;

return true;

}

}

package edu.ilstu;

import java.io.File;

import java.io.FileWriter;

import java.io.IOException;

public class Track {

private Reservation[] reservations = new Reservation[40];

public class Track {

private Reservation[] reservations = new Reservation[40];

public Reservation[] getReservations() {

return reservations;

}

public void setReservations(Reservation[] reservations) {

this.reservations = reservations;

}

public boolean addReservation(Reservation reservation) {

for (int i = 0; i < reservations.length; i++) {

if (reservations[i] == null) {

reservations[i] = reservation;

return true;

}

}

return false;

}

}

return false;

}

public void printItinerary(String reservationNumber) {

for (Reservation reservation : reservations) {

if (reservation.getReservationNumber().equals(reservationNumber)) {

System.out.println(reservation);

}

}

}

public void printAllItinerary() {

for (Reservation reservation : reservations) {

System.out.println(reservation);

System.out.println();

}

}

}

}

public void writeToFile(File file) throws IOException {

if (file == null) {

return;

}

if (!file.exists()) {

file.createNewFile();

}

FileWriter fileWriter = new FileWriter(file);

for (Reservation reservation : reservations) {

fileWriter.write(reservation.toString());

}

fileWriter.close();

}

}

package edu.ilstu;

}

package edu.ilstu;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Route {

public final static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("mm/dd/yyyy");

private int routeNumber;

private Date routeDate;

private String departureTrack;

private String arrivalTrack;

private String arrivalTime;

private String departureTime;

private String seat;

public Route() {

}

public Route(int routeNumber, Date routeDate, String departureTrack, String arrivalTrack, String arrivalTime,

String departureTime, String seat) {

this.routeNumber = routeNumber;

this.departureTrack = departureTrack;

this.arrivalTrack = arrivalTrack;

this.arrivalTime = arrivalTime;

this.departureTime = departureTime;

this.seat = seat;

}

public int getRouteNumber() {

return routeNumber;

}

public void setRouteNumber(int routeNumber) {

this.routeNumber = routeNumber;

}public Date getRouteDate() {

return routeDate;

}

public void setRouteDate(Date routeDate) {

this.routeDate = routeDate;

}

public String getDepartureTrack() {

return departureTrack;

}

public void setDepartureTrack(String departureTrack) {

this.departureTrack = departureTrack;

}

this.departureTrack = departureTrack;

}

public String getArrivalTrack() {

return arrivalTrack;

}

public void setArrivalTrack(String arrivalTrack) {

this.arrivalTrack = arrivalTrack;

}

public String getArrivalTime() {

return arrivalTime;

}

public void setArrivalTime(String arrivalTime) {

this.arrivalTime = arrivalTime;

}

public String getDepartureTime() {

return departureTime;

}

public void setDepartureTime(String departureTime) {

this.departureTime = departureTime;

}

public String getSeat() {

return seat;

}

public void setSeat(String seat) {

this.seat = seat;

}

@Override

public String toString() {

return "Route Number=" + routeNumber + ", route Date=" + DATE_FORMAT.format(routeDate) + "\n departureTrack:-\n"+ departureTrack + "\narrivalTrack:- \n" + arrivalTrack + ", arrivalTime=" + arrivalTime+ ", departureTime=" + departureTime + ", seat=" + seat;+ ", departureTime=" + departureTime + ", seat=" + seat;

}

@Override

public int hashCode() {

final int prime = 31;

int result = 1;

result = prime * result + ((routeDate == null) ? 0 : routeDate.hashCode());

result = prime * result + routeNumber;

return result;

}

@Override

public boolean equals(Object obj) {

if (this == obj)

return true;

if (obj == null)

return false;

if (getClass() != obj.getClass())

return false;

Route other = (Route) obj;

if (routeDate == null) {

if (other.routeDate != null)

return false;

} else if (!routeDate.equals(other.routeDate))

return false;

if (routeNumber != other.routeNumber)

return false;

return true;

}

}

package edu.ilstu;

import java.io.File;

import java.io.IOException;

import java.util.Scanner;

public class TrackOutput {

public void transactions(File file, Track track) throws IOException {

if (file == null || !file.exists()) {

return;

}

Scanner scanner = new Scanner(file);

while (scanner.hasNext()) {

switch (scanner.nextInt()) {

case 1:

String name = scanner.nextLine();

String reservationNUmber = scanner.nextLine();

Route departureRoute = null;

try {

departureRoute = new Route(scanner.nextInt(), Route.DATE_FORMAT.parse(scanner.nextLine()),

scanner.nextLine(), scanner.nextLine(), scanner.nextLine(), scanner.nextLine(),

scanner.nextLine());

} catch (Exception e) {

e.printStackTrace();

}

Route returnRoute = null;

try {

returnRoute = new Route(scanner.nextInt(), Route.DATE_FORMAT.parse(scanner.nextLine()),

scanner.nextLine(), scanner.nextLine(), scanner.nextLine(), scanner.nextLine(),

scanner.nextLine());

} catch (Exception e) {

e.printStackTrace();

}

track.addReservation(new Reservation(name, reservationNUmber, departureRoute, returnRoute));

break;

case 2:

track.printItinerary(scanner.nextLine());

break;

case 3:

track.printAllItinerary();

break;

case 4:

track.writeToFile(new File("UpdatedData.txt"));

break;

default:

break;

}

}

scanner.close();

}

}

Add a comment
Know the answer?
Add Answer to:
This is in Java The Problem: A common task in computing is to take data and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1.Identify functional dependencies and derive candidate keys, and 2.Follow the normalization process to determine tables and...

    1.Identify functional dependencies and derive candidate keys, and 2.Follow the normalization process to determine tables and relationships based on eight tables (AIRPORT, FLIGHT, DEPARTURES, PASSENGER, RESERVATION, EQUIP_TYPE, PILOTS, and TICKET) that contain data about the Belle Airlines. Download and use data in Project 3 zip file for this project. Some Background on Belle Airlines Belle Airlines is a regional carrier that operates primarily in the southwestern United States. At the present time, Belle Airlines operates its own reservation information system....

  • JAVA ONLY Design two classes: Flight and Itinerary. The Flight class stores the information about a...

    JAVA ONLY Design two classes: Flight and Itinerary. The Flight class stores the information about a flight with the following members: 1. A data field named flightNo of the String type with getter method. 2. A data field named departureTime of the GregorianCalendar type with getter and setter methods. 3. A data field named arrivalTime of the GregorianCalendar type with getter and setter methods. 4. A constructor that creates a Flight with the specified number, departureTime, and arrivalTime. 5. A...

  • Consider the data file “assignment-07-input.csv. The data contains of 4 different things separated by comma –...

    Consider the data file “assignment-07-input.csv. The data contains of 4 different things separated by comma – origin airport code (3 characters), destination airport code (3 characters), airline code (2 characters), passenger count (integer). There is no header row, so you do not have to deal with it. Write code to do the following: • The program will take 3 extra command line arguments & use a makefile to run. o Input file name o Output file name o Airline code...

  • Using python beginner code see example code of what to use for this assignment we have...

    Using python beginner code see example code of what to use for this assignment we have gathered together some interesting data into a file called harvardLightning.txt The file contains all recorded lightning strikes in the harvard area Parsing Review alist = str.split()                  # alist will contain the elements of str - split using whitespace Specifying a delimiter Examples: delimiter = ',' delimiter = '-', delimiter = ';' Stripping specified characters Example: astring.strip('\n') Avoid blank lines: if len(line) == 0:                                             ...

  • the first question java code eclipse app the second question is java fx gui caculator please...

    the first question java code eclipse app the second question is java fx gui caculator please fast 1. Create project called "YourFirstName_QUID'. Eg. Aliomar_202002345 2. Create two package Q1 and Q2. 3. Add your name and studentID as comments on the top of each Java source file you submit. Question 1. Bookings APP [80 Points-six parts] Implement the following hotel booking system. Use the following class diagram to understand the structure of the system's classes, their attributes operations (or methods),...

  • Oliò Description and Requirements Computer Lab Assignment #9 1. Use Excel and the "Restaurant" da...

    oliò Description and Requirements Computer Lab Assignment #9 1. Use Excel and the "Restaurant" data set file located in D2L for this assignment 2. For each class (Class 1 to 14), consider the number of customers for day 7. Call this new variable, day data, as X1. Consider the number of waiters/waitresses as variable X2.Consider the customer satisfaction as vanable Y In another word, create a table for variables Y, X.X2 Dependent Variable: Y Independent Variables: X,X2 3. Find a...

  • A test specification provides designers with what needs to be known in order to perform a...

    A test specification provides designers with what needs to be known in order to perform a specific test, and to validate and verify the requirement to be tested. The test script is divided into the test script, which is the generic condition to be tested, and one or more test cases within the test script. Provide a test script and test case for at least 3 of your requirements identified in your requirements specification. Provide the following format for an...

  • Objectives: 1. Use if, switch, and loop statements 2. Use input and output statements 3. Incorporate...

    Objectives: 1. Use if, switch, and loop statements 2. Use input and output statements 3. Incorporate functions to divide the program into smaller segments Instructions: Your task is to write a program that simulates a parking meter within the parking deck. The program will start by reading in the time a car arrives in the parking deck. It will then ask you what time the car left the parking deck. You should then calculate the time that has passed between...

  • Java code BIRTHDAY GRAPH5 4B Input Standard input Output Standard output Topic Array & Array Processing...

    Java code BIRTHDAY GRAPH5 4B Input Standard input Output Standard output Topic Array & Array Processing Birthday Graph Problem Description Everyone loves to be celebrated on their birthdays. Birthday celebration can encourage positive social E interaction among co-workers, foster friendship among classmates or even strengthen bond between E BOBO Birthday graph can be display in many forms. It can a creative drawing consists of cupcakes, balloons, UU candles with names, or it can be in the form of simple bar...

  • (JAVA) Use the Pet.java program from the original problem (down below) Compile it. Create a text...

    (JAVA) Use the Pet.java program from the original problem (down below) Compile it. Create a text file named pets10.txt with 10 pets (or use the one below). Store this file in the same folder as your “class” file(s). The format is the same format used in the original homework problem. Each line in the file should contain a pet name (String), a comma, a pet’s age (int) in years, another comma, and a pet’s weight (double) in pounds. Perform the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT