Question

in java Write a class called Flight that represents an airline flight. (50 pts) It should...

in java

  1. Write a class called Flight that represents an airline flight. (50 pts)
    1. It should contain instance data that represents the airline name, flight number, departure city, destination cities, and flight price.
    2.   Define the Flight constructor to accept and initialize all instance data.
    3.   Overload the Flight constructor such that the initial value of instance data airline name by Delta.
    4.   Include getter and setter methods for all instance data.
    5.   Include a toString method that returns a one-line description of the flight.
  2. Create a driver class called FlightDemo with main method. (10 pts)
    1. Driver class instantiates at least three flight objects and output these airline information.
    2.   Driver class create one flight object to read, update and output one delta flight information.

For 2.1 example:

Set information about three airlines:

"US Air", "Boston", "Los Angeles", 347, 345.67

"Delta", "Philadelphia", "London", 212, 1200.00

"Continental", "Atlanta", "Chicago", 822, 225.25

Output information:

US Air 347 –- From: Boston To: Los Angeles -- price: $345.67

Delta 212 –- From: Philadelphia To: London –- price: $1200.00

Continental 822 –- From: Atlanta To: Chicago –- price: $225.25

0 0
Add a comment Improve this question Transcribed image text
Answer #1

class Flight
{
   String name;
   int flightNumber;
   String departure;
   String destination;
   double price;
   Flight(String name,int flightNumber,String departure,String destination,double price)
   {
       this.name=name;
       this.flightNumber=flightNumber;
       this.departure=departure;
       this.destination=destination;
       this.price=price;
   }
   Flight(int flightNumber,String departure,String destination,double price)
   {
       this.name="Delta";
       this.flightNumber=flightNumber;
       this.departure=departure;
       this.destination=destination;
       this.price=price;
   }  
   public String getName()
   {
       return name;
   }
   public void setName(String name)
   {
       this.name=name;
   }
   public int getflightNumber()
   {
       return this.flightNumber;
   }
   public void setflightNumber(int flightNumber)
   {
       this.flightNumber=flightNumber;
   }
   public String getDeparture()
   {
       return departure;
   }
   public void setDeparture(String departure)
   {
       this.departure=departure;
   }
   public String getDestination()
   {
       return destination;
   }
   public void setDestination(String destination)
   {
       this.destination=destination;
   }
   public double getPrice()
   {
       return price;
   }
   public void setPrice(double price)
   {
       this.price=price;
   }
   public String toString()
   {
       return name+" "+flightNumber+" --- From: "+departure+" To: "+destination+" --- price: $"+price;
   }  
}
public class FlightDemo
{
   public static void main(String[] args)
   {
       Flight f1 = new Flight("US Air",347,"Boston","Los Angeles",345.67);
       Flight f2 = new Flight(212,"Philadelphia","London",1200.00);
       Flight f3 = new Flight("Continental",822,"Atlanto","Chicago",225.25);
       System.out.println(f1.toString());
       System.out.println(f2.toString());
       System.out.println(f3.toString());
   }
}

Add a comment
Know the answer?
Add Answer to:
in java Write a class called Flight that represents an airline flight. (50 pts) It should...
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
  • Design and implement a class called Flight that represents an airline flight. It should contain instance data that represents the airline name

    Design and implement a class called Flight that represents an airline flight. It should contain instance data that represents the airline name, 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 objects.

  • Write a class called Shelf that contains instance data that represents the length, breadth, and capacity...

    Write a class called Shelf that contains instance data that represents the length, breadth, and capacity of the shelf. Also include a boolean variable called occupied as instance data that represents whether the shelf is occupied or not. Define the Shelf constructor to accept and initialize the height, width, and capacity of the shelf. Each newly created Shelf is vacant (the constructor should initialize occupied to false). Include getter and setter methods for all instance data. Include a toString method...

  • cs55(java) please. Write a class called Book that contains instance data for the title, author, publisher,...

    cs55(java) please. Write a class called Book that contains instance data for the title, author, publisher, price, and copyright date. Define the Book constructor to accept and initialize this data. Include setter and getter methods for all instance data. Include a toString method that returns a nicely formatted, multi-line description of the book. Write another class called Bookshelf, which has name and array of Book objects. Bookself capacity is maximum of five books. Includes method for Bookself that adds, removes,...

  • TravelAir.com samples domestic airline flights to explore the relationship between airfare and distance. The service would...

    TravelAir.com samples domestic airline flights to explore the relationship between airfare and distance. The service would like to know if there is a correlation between airfare and flight distance. If there is a correlation, what percentage of the variation in airfare is accounted for by distance? How much does each additional mile add to the fare? The data follow. Distance Fare 636 $109 2,395 252 2,176 221 605 151 403 138 1,258 209 254 627 259 264 2,342 215 177...

  • java code Write a class called FractionObject that represents a fraction with an integer numerator and...

    java code Write a class called FractionObject that represents a fraction with an integer numerator and denominator as fields. A Fraction Object object should have the following methods: A constructor with int numerator, int denominator as parameters - Constructs a new fraction object to represent the ratio (numerator/denominator). The denominator cannot be 0, so output a message if O is passed and set the numerator and denominator to 1. A constructor with no parameters - Constructs a new FractionObject to...

  • Java : I keep getting something wrong in my loadfile method, how do I fix my...

    Java : I keep getting something wrong in my loadfile method, how do I fix my code? Thank you. here is what is contained in the text file (WorldSeriesWinners.txt) 112 1903 Boston Americans 1904 No World Series 1905 New York Giants 1906 Chicago White Sox 1907 Chicago Cubs 1908 Chicago Cubs 1909 Pittsburgh Pirates 1910 Philadelphia Athletics 1911 Philadelphia Athletics 1912 Boston Red Sox 1913 Philadelphia Athletics 1914 Boston Braves 1915 Boston Red Sox 1916 Boston Red Sox 1917 Chicago...

  • Chapter 5 Assignment Read directions: In JAVA design and implement a class called Dog that contains...

    Chapter 5 Assignment Read directions: In JAVA design and implement a class called Dog that contains instance data that represents the dog's name and dog's age. Define the Dog constructor to accept and initialize instance data. Include getter and setter methods for the name and age. Include a method to compute and return the age of the dog in "person years" (seven times age of dog. Include a toString method that returns a one-time description of the dog (example below)....

  • how would i write code in java/netbeans for this: You will be creating the driver class...

    how would i write code in java/netbeans for this: You will be creating the driver class for this homework (PA05_TVs.java) and the object/element class, TV.java. Your TV class should include only a channel value for instance data (3-99) and the following methods: constructor [requires an initial channel value], getter, setter, randomChannel() [does not return the new channel value], and toString(). The driver class must complete the following: Instantiate a TV object and set the initial channel to 97. Instantiate a...

  • 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....

  • Java Project For this assignment, you will write a simulation program to determine the average waiting...

    Java Project For this assignment, you will write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: delete the addfirst, addlast, and add(index) methods and instead include a single add method...

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