Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please see attached picture. This code should be implemented on Netbeans Java. please make sure it works Thank you Simple flight booking system Flight Booking

Please see attached picture.
This code should be implemented on Netbeans Java.
please make sure it works
Thank you
Simple flight booking system
image text in transcribed
image text in transcribed
image text in transcribed
Flight Booking System Implement a very simple model of a flight booking system. In our model, we will have Flight objects (representing flights) and we have passengers (either a frequent flyer member or a non-member) who want to book a flight for a travel. If a seat is available in a given flight, then a ticket will be issued at a price depending on whether the ticket is for a member or a non-member. To develop this system, we will need six classes. I. Flight class: (a) Implementing the Flight class: Each object of this class represents a flight. The Flight class consists of instance variables, a constructor and instance methods. This class has seven instance variables: o flightNumber of type int o origin of type String o destination of type String o departure Time of type String o capacity of type int o numberOfSeatsLeft of type int o original Price of type double This class should have: a constructor that initializes the instance variables. It takes six parameters. If the specified origin and destination are equal, an IllegalArgumentException should be thrown to abort the construc- tion. The numberOfSeatsLeft variable is initialized depending on the specified capacity. getters and setters for each instance variable. Page 1 of 4 a bookASeat() method. If the numberOfSeatsLeft is greater than 0. this method decrements the numberOfSeatsLeft variable and returns true. Otherwise, it returns false. This class should override the toString method that returns a String representation of a Flight object. The String should include the flight number, the origin, the destination, the departure time and the original price. c.g., "Flight 1030, Toronto to Kolkata, 03/02/99 7:50 pm, original price: 1000S" (b) Testing the Flight class (use JUnit 4): Once the Flight class has no compilation errors: Write the code for the junit test method test constructor that tests the constructor by providing it with valid arguments. Write a JUnit test method testInvalidConstructor() that tests the constructor with invalid arguments. The test should pass only if an IllegalArgumentException is thrown. Test the public methods that include all the getters, setters, the bookASeat () method and the toString() method, using Junit. II. Ticket class: This class represents a flight ticket. This class has four instance variables: o passenger of type Passenger o flight of type Flight o price of type double o number of type int. Each Ticket has a unique ticket number (the first Ticket has ticket number 1, the second has ticket number 2, etc. (Hint implementing this will require adding a static variable.) This class should have a constructor that takes three parameters: Passenger p, Flight flight, double price. It should initialize all the instance variables accordingly. getters and setters for each instance variable. override the toString() method that returns a String representation of a Ticket object. The String should include the passenger's name, information about the flight (eg, the flight num- ber, the origin, the destination, the departure, and the original price) and the actual ticket price.e.g., "Julia Chow, Flight 1030, Toronto to Kolkata, 03/02/99 7:50 pm, original price: 1000$, ticket price: $600,00" III. Passenger class: This is an abstract class. The subclasses of this class are: Member and NonMember. The class has attributes common to all kinds of passengers. It contains two instance variables: name of type String age of type int This class should have a constructor for initializing the instance variables, getters and setters for each instance variable. This class also has an abstract method double applyDiscount (double p). This method should be overridden by both the subclasses. In the subclasses, this applyDiscount method should return a price after applying the appropriate discount. IV. Member class: A Member object represents a frequent flyer member. This class has one instance variable: yearsOfMembership of type int This class extends the Passenger class and overrides the applyDiscount ( double p) method as follows. If the member has membership for more than 5 years, then 50% discount will be applied. If the member has membership for more than 1 year but less than or equal to 5 years, then 10% discount will be applied. Otherwise no discount. V. Non Member class: A NonMember object represents a passenger who is not a frequent flyer member. This class has no instance variables. This class extends the Passenger class and overrides the applyDiscount (double p) method as follows. If the age of the person is more than 65, 10% discount will be applied. Otherwise no discount. VI. Manager class: A Manager object manages the flights of a specific airline. It maintains an array of flights and an array of issued tickets. It should have the following methods: public void createFlights(): this method should populate the array of flights. public void displayAvailableFlights(String origin, String desti- nation): this method should display all the available flights from origin to destination. It should display only those flights that are not yet fully booked. public Flight getFlight(int flight Number): this method should return the Flight object for the specified flight number. public void bookSeat(int flight Number, Passenger p): This method first tries to find a flight for the given flight number. If such flight exists, then it tries to book a seat in that flight. If booking is successful, then applies the appropriate discount on the price de- pending on the passenger being a member or a non-member (Polymorphism works here). Final- ly, it issues a ticket with the appropriate price. public static void main(String[] args): this method should call all the other methods of the Manager class to see if they work. You are responsible for developing a con- vincing plan for the main method, i.e., for convincing the TA that your methods work properly

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Oriented Databases Prentice Hall International Series In Computer Science

Authors: John G. Hughes

1st Edition

0136298745, 978-0136298748

More Books

Students also viewed these Databases questions