Question

In: Computer Science

public class Flight extends java.lang.Object This class represents a single flight within the travel agency system....

public class Flight
extends java.lang.Object

This class represents a single flight within the travel agency system.

    • Constructor Summary

      Constructors
      Constructor and Description
      Flight(java.lang.String airline, int flightNum, java.lang.String from, java.lang.String to, java.util.Calendar leavesAt, java.util.Calendar arrives, double price)

      Creates a new flight leg in the system.

    • Method Summary

      All Methods Instance Methods Concrete Methods
      Modifier and Type Method and Description
      double getPrice()

      Retrieves the price of this flight.

      java.lang.String toString()

      Retrieves a formatted string summarizing this Flight.

      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Flight

        public Flight(java.lang.String airline,
                      int flightNum,
                      java.lang.String from,
                      java.lang.String to,
                      java.util.Calendar leavesAt,
                      java.util.Calendar arrives,
                      double price)

        Creates a new flight leg in the system.

        Parameters:

        airline - The two letter airline code (e.g, "DL", "AA")

        flightNum - The unique flight number on a given day

        from - The three letter airport code for the departure airport (e.g, "OMA")

        to - The three letter airport code for the arrival airport (e.g., "CDG")

        leavesAt - The departure time

        arrives - The arrival time

        price - The price for this flight in US Dollars.

Solutions

Expert Solution

/**************************Flight.java************************/

import java.util.Calendar;

public class Flight {

   private String airline;
   private int flightNum;
   private String from;
   private String to;
   private Calendar leavesAt;
   private Calendar arrives;
   private double price;

   public Flight(String airline, int flightNum, String from, String to, Calendar leavesAt, Calendar arrives,
           double price) {
       this.airline = airline;
       this.flightNum = flightNum;
       this.from = from;
       this.to = to;
       this.leavesAt = leavesAt;
       this.arrives = arrives;
       this.price = price;
   }

   public double getPrice() {
       return price;
   }

   public String getAirline() {
       return airline;
   }

   public int getFlightNum() {
       return flightNum;
   }

   public String getFrom() {
       return from;
   }

   public String getTo() {
       return to;
   }

   public Calendar getLeavesAt() {
       return leavesAt;
   }

   public Calendar getArrives() {
       return arrives;
   }

   @Override
   public String toString() {
       return "Airline: " + airline + "\nFlight Number: " + flightNum + "\nFrom: " + from + "\nTo: " + to
               + "\nLeaves At: " + leavesAt.getTime().toString() + "\nArrives At: " + arrives.getTime().toString() + "\nPrice: $" + price + "\n";
   }

}
/************************TestFlight.java**********************./

import java.util.Calendar;

public class TestFlight {

   public static void main(String[] args) {

       Calendar leaveAt = Calendar.getInstance();
       leaveAt.set(Calendar.YEAR, 2020);
       leaveAt.set(Calendar.MONTH, 10);
       leaveAt.set(Calendar.DAY_OF_MONTH, 26);
       leaveAt.set(Calendar.HOUR_OF_DAY, 5);
       leaveAt.set(Calendar.MINUTE, 34);
       Calendar arriveAt = Calendar.getInstance();
       arriveAt.set(Calendar.YEAR, 2020);
       arriveAt.set(Calendar.MONTH, 10);
       arriveAt.set(Calendar.DAY_OF_MONTH, 31);
       arriveAt.set(Calendar.HOUR_OF_DAY, 7);
       arriveAt.set(Calendar.MINUTE, 12);
       Flight f1 = new Flight("DL", 5, "OMA", "CDG", leaveAt, arriveAt, 234);
       System.out.println("Flight information");

       System.out.println(f1.toString());
   }
}
/****************output************/

Flight information
Airline: DL
Flight Number: 5
From: OMA
To: CDG
Leaves At: Thu Nov 26 05:34:17 IST 2020
Arrives At: Tue Dec 01 07:12:17 IST 2020
Price: $234.0

Please let me know if you have any doubt or modify the answer, Thanks :)


Related Solutions

JAVA - Design and implement a class called Flight that represents an airline flight. It should...
JAVA - Design and implement a class called Flight that represents an airline flight. It should contain instance data that represent the airline name, the flight number, and the flight’s origin and destination cities. Define the Flight constructor to accept and initialize all instance data. Include getter and setter methods for all instance data. Include a toString method that returns a one-line description of the flight. Create a driver class called FlightTest, whose main method instantiates and updates several Flight...
1. A travel agency would like to track the destination of each flight. Given the following...
1. A travel agency would like to track the destination of each flight. Given the following business rule, what constraint(s) can you apply to the flight table, given there is also a destination table? "A flight must be associated with a destination". Question 1 options: Referential integrity Check constraint Nullability Default constraint 2. Constraint applied to a one-to-many relationship when a referenced record (on the 1 side) is deleted, then the referencing records (on the Many side) should also be...
Consider the following code: public class Bay extends Lake { public void method1() { System.out.println("Bay 1");...
Consider the following code: public class Bay extends Lake { public void method1() { System.out.println("Bay 1"); super.method2(); } public void method2() { System.out.println("Bay 2"); } } //********************************* class Pond { public void method2() { System.out.println("Pond 2"); } } //************************** class Ocean extends Bay { public void method2() { System.out.println("Ocean 2"); } } //********************************* class Lake extends Pond { public void method3() { System.out.println("Lake 3"); method2(); } } //**************************** class Driver { public static void main(String[] args) { Object var4 =...
How can the classes be modified to satisfy the comments: public class InvalidIntegerException extends Exception{    ...
How can the classes be modified to satisfy the comments: public class InvalidIntegerException extends Exception{     // Write a class for an InvalidIntegerException here     //Constructor that takes no arguments public InvalidIntegerException (){ super(); } //Constructor that takes a string message public InvalidIntegerException (String message){ super(message); } } import java.io.InputStream; import java.io.IOException; public class Parser { private InputStream in; public static final int CHAR_ZERO = (int) '0'; public Parser (InputStream in) { this.in = in; } // Complete the following...
If exactly 186 people sign up for a charter flight, Leisure World Travel Agency charges $302/person....
If exactly 186 people sign up for a charter flight, Leisure World Travel Agency charges $302/person. However, if more than 186 people sign up for the flight (assume this is the case), then each fare is reduced by $1 for each additional person. Determine how many passengers will result in a maximum revenue for the travel agency. Hint: Let x denote the number of passengers above 186. Show that the revenue function R is given by R(x) = (186 +...
Package pacman.score Class ScoreBoard Object ScoreBoard public class ScoreBoard extends Object ScoreBoard contains previous scores and...
Package pacman.score Class ScoreBoard Object ScoreBoard public class ScoreBoard extends Object ScoreBoard contains previous scores and the current score of the PacmanGame. A score is a name and value that a valid name only contains the following characters: A to Z a to z 0 to 9 and must have a length greater than 0. The value is a integer that is equal to or greater than 0. Implement this for Assignment 1 Constructor Summary Constructors Constructor Description ScoreBoard() Creates...
Package pacman.score Class ScoreBoard Object ScoreBoard public class ScoreBoard extends Object ScoreBoard contains previous scores and...
Package pacman.score Class ScoreBoard Object ScoreBoard public class ScoreBoard extends Object ScoreBoard contains previous scores and the current score of the PacmanGame. A score is a name and value that a valid name only contains the following characters: A to Z a to z 0 to 9 and must have a length greater than 0. The value is a integer that is equal to or greater than 0. Implement this for Assignment 1 Constructor Summary Constructors Constructor Description ScoreBoard() Creates...
Using this BubbleSort implementation in Java: public class BubbleSort<T extends Comparable<T>> {    private static <T...
Using this BubbleSort implementation in Java: public class BubbleSort<T extends Comparable<T>> {    private static <T extends Comparable<T>>    void swap(T[] data, int index1, int index2)    {       T temp = data[index1];       data[index1] = data[index2];       data[index2] = temp;    }    public void sort(T[] data)    {       int position, scan;       for (position = data.length - 1; position >= 0; position--)       {          for (scan = 0; scan <= position - 1; scan++)          {...
Disfrutar Travel Agency is considering two different computer systems: the Standard T2 System and the Custom...
Disfrutar Travel Agency is considering two different computer systems: the Standard T2 System and the Custom Travel System. The projected annual revenues, annual costs, capital outlays, and project life for each system (in after-tax cash flows) are as follows: Standard T2 Custom Travel Annual revenues $360,000 $450,000 Annual operating costs 180,000 240,000 System investment 540,000 530,000 Project life 5 years 5 years Assume that the cost of capital for the company is 12 percent. The present value tables provided in...
Using maps in Java. Make a public class called ExampleOne that provides a single class (static)...
Using maps in Java. Make a public class called ExampleOne that provides a single class (static) method named firstOne. firstOne accepts a String array and returns a map from Strings to Integer. The map must count the number of passed Strings based on the FIRST letter. For example, with the String array {“banana”, “apples”, “blueberry”, “orange”}, the map should return {“b”:2, “a”:1, “o”:1}. Disregard empty Strings and zero counts. Retrieve first character of String as a char using charAt, or,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT