Q5) Write a complete Java program that defines the following: 1) Class Passenger with the following specifications: Instance variables: name: name of the passenger of type string ticketPrice: price of the passenger's ticket of type double Methods: - full-parameterized constructor: a constructor method used to initialize the instantiated objects - tostring(): return name and ticket price of the passenger 2) class Flight with the following specifications: Instance variables: - noofSeats: number of available seats of type integer date: date of the flight of type java.util.Date passengers: array of passengers of type Passenger for a given flight. Use ArrayList for simplicity Methods: full-parameterized constructor: a constructor method used to initialize the instantiated objects Flight (int noofSeats, Date date) addPassenger(Passenger p): add passenger to the ArrayList passengers. Use add() method of ArrayList to add passebgers. Addition of passengers should not exceed the number of available seats (noofSeats). sum(): return the sum of prices of all tickets toString(): return the date and passengers (name, ticket price) of the flight 3) Driver class that creates an object of type Flight, add passengers to it, and finally print the object's date, passengers, and total price of all tickets. The output should look like the following: Sorry Ahmed the flight is fully booked Flight Data: Date (02/3/2021) ( (Mohammed, 2500.0), (Yaser, 3500.0)) Total tickets price: 6000.0

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Q5) Write a complete Java program that defines the following:
1) Class Passenger with the following specifications:
Instance variables:
name: name of the passenger of type string
ticketPrice: price of the passenger's ticket of type double
Methods:
- full-parameterized constructor: a constructor method used to initialize the
instantiated objects
- tostring(): return name and ticket price of the passenger
2) class Flight with the following specifications:
Instance variables:
- noofSeats: number of available seats of type integer
date: date of the flight of type java.util.Date
passengers: array of passengers of type Passenger for a given flight. Use ArrayList
for simplicity
Methods:
- full-parameterized constructor: a constructor method used to initialize the
instantiated objects
Flight (int noofSeats, Date date)
- addPassenger(Passenger p): add passenger to the ArrayList passengers. Use add()
method of ArrayList to add passebgers. Addition of passengers should not exceed
the number of available seats (noofSeats).
sum(): return the sum of prices of all tickets
- toString(): return the date and passengers (name, ticket price) of the flight
3) Driver class that creates an object of type Flight, add passengers to it, and finally print
the object's date, passengers, and total price of all tickets. The output should look like
the following:
Sorry Ahmed the flight is fully booked
Flight Data: Date (02/3/2021)
[ (Mohammed, 2500.0), (Yaser, 3500.0)]
Total tickets price: 6000.0
Transcribed Image Text:Q5) Write a complete Java program that defines the following: 1) Class Passenger with the following specifications: Instance variables: name: name of the passenger of type string ticketPrice: price of the passenger's ticket of type double Methods: - full-parameterized constructor: a constructor method used to initialize the instantiated objects - tostring(): return name and ticket price of the passenger 2) class Flight with the following specifications: Instance variables: - noofSeats: number of available seats of type integer date: date of the flight of type java.util.Date passengers: array of passengers of type Passenger for a given flight. Use ArrayList for simplicity Methods: - full-parameterized constructor: a constructor method used to initialize the instantiated objects Flight (int noofSeats, Date date) - addPassenger(Passenger p): add passenger to the ArrayList passengers. Use add() method of ArrayList to add passebgers. Addition of passengers should not exceed the number of available seats (noofSeats). sum(): return the sum of prices of all tickets - toString(): return the date and passengers (name, ticket price) of the flight 3) Driver class that creates an object of type Flight, add passengers to it, and finally print the object's date, passengers, and total price of all tickets. The output should look like the following: Sorry Ahmed the flight is fully booked Flight Data: Date (02/3/2021) [ (Mohammed, 2500.0), (Yaser, 3500.0)] Total tickets price: 6000.0
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY