
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
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](https://content.bartleby.com/qna-images/question/b29e1509-3151-4975-aa56-1cd4f8a94346/ac8ed4dc-a035-4d2c-af6b-76a5d22b68a3/w9326pe_thumbnail.jpeg)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 2 images

Knowledge Booster
Similar questions
- 1)Create a complete Java class that can be used to create a Computer object as described below:A Computer has a:- Manufacturer- Disk Size- Manufacturing Date- Number of coresa) Add all instance variables (data encapsulation is expected).b) The class must have getters and setters for all instance variables.c) The class must have two constructors: a no-arg constructor and a constructor thatreceives input parameters for each instance variable.d) Implement a toString() method for your class. 2)Write a Java program TestComputer, which creates three Computer objects with the informationbelow:a) - Manufacturer: Dell- Disk Size: 1189160321024 bytes- Manufacturing Date: April 1, 2020- Number of cores: 2b) - Manufacturer: Apple Inc- Disk Size: 269283712040 bytes- Manufacturing Date: March 31, 2020- Number of cores: 4c) Create your own Object. You can mimic your actual personal computer or use a no-argsconstructor.Print the three objects using toString() method to show all data fieldsarrow_forwarduse the following partial class definitions:public class A1{public int x;private int y;public int z;…}public class A2 extends A1{public int a;private int b; …}public class A3 extends A2{private int q;…} 2) Which of the following lists of instance data are accessible in class A2?a) x, y, z, a, bb) x, y, z, ac) x, z, a, bd) z, a, be) a, barrow_forwardCan you give me the solution in javaarrow_forward
- a.)Write a Java statement that increments the value of count by 1. b.) Write a Java statement that outputs the value of count. C.) Write the 6 definition of constructors and the methods of the class MyClass as described in its definition.arrow_forward6 Javaarrow_forwardA programmer has submitted the following class declaration for approval. This will be part of a program that tracks departments within a company and employees assigned to those departments. class Employee { public: Employee(); string getName(); long getldentifier(); Dollars getSalary(): Department worksln(): void assignTo (Department"); Employee getSupervisor() (return dept->getManager();) private: string name; long identifier; Department" dept; Dollars salary: Based upon this information, which of the C++ checklist items appear to be in violation? O Interface completeness O Meaningful names O Undocumented pre-conditions O All data members private O Every constructor initializes every data member O Appropriate treatment of default constructor O Appropriate treatment of the Big 3 O Appropriate relational operators O Appropriate output function D Const correctnessarrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

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 Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

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
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY