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...
public class Mammal extends SeaCreature { public void method1() { System.out.println("warm-blooded"); } } public class SeaCreature...
public class Mammal extends SeaCreature { public void method1() { System.out.println("warm-blooded"); } } public class SeaCreature { public void method1() { System.out.println("creature 1"); } public void method2() { System.out.println("creature 2"); } public String toString() { return "ocean-dwelling"; } } public class Whale extends Mammal { public void method1() { System.out.println("spout"); } public String toString() { return "BIG!"; } } public class Squid extends SeaCreature { public void method2() { System.out.println("tentacles"); } public String toString() { return "squid"; } } What...
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...
write the following programs: Ram.java, Truck.java, LandVehicle.java and Vehicle.java. public class Ram extends Truck { public...
write the following programs: Ram.java, Truck.java, LandVehicle.java and Vehicle.java. public class Ram extends Truck { public static void main(String[] args) { // your implementation } public Ram() { // your implementation } } public class Truck extends LandVehicle { public Truck() { // your implementation } public Truck(String s) { // your implementation } } public class LandVehicle extends Vehicle { public LandVehicle() { // your implementation } } public class Vehicle { public Vehicle() { // your implementation
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 =...
Consider the following classes: public class Clock extends Bear { public void method3() { System.out.println("Clock 3");...
Consider the following classes: public class Clock extends Bear { public void method3() { System.out.println("Clock 3"); } } public class Lamp extends Can { public void method1() { System.out.println("Lamp 1"); } public void method3() { System.out.println("Lamp 3"); } } public class Bear extends Can { public void method1() { System.out.println("Bear 1"); } public void method3() { System.out.println("Bear 3"); super.method3(); } } public class Can { public void method2() { System.out.println("Can 2"); method3(); } public void method3() { System.out.println("Can 3"); }...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT