Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

the slution of this question in java language In this assignment, you are required the following classes: Passenger + name: String - ticketNo: int -

the slution of this question in java language
image text in transcribed
image text in transcribed
In this assignment, you are required the following classes: Passenger + name: String - ticketNo: int - luggage: Luggage + Passenger) + Passenger(name: String, ticketNo: int) + getTicketNo(): int + getLuggage(): Luggage +toString(): String Luggage - numOfBags: int=1 -weight: double-25 +Luggagel) + Luggage(numOfBags:int, weight: double) + getNumOfBags(): int + get Weight(): double + toString(): String FirstClass Economy - extraLuggage: Luggage - mealAdded: boolean + FirstClass() + Economy + FirstClass(name: String, ticketNo:int) + Economy( name: String, ticketNo:int, mealAdded: boolean) + getLuggage(): Luggage + isMealAdded():boolean + setMealAdded(mealAdded:boolean):void +toStringO: String 1. Luggage: The no-arg constructor must initialize the data fields to their defaults. For this class you are required to override the toString method such that it returns a String that includes the number of bags and the weight as in the following example: 2 bags. 40 kg Number of weight bags 2. Passenger: The no-arg constructor Passenger() must read the name and the ticktNo from the user. You must prompt the user to enter the name and ticketNo with appropriate messages. It must also ask the user if he wants to add additional luggage, if no it must create a luggage object with default values. If yes, it must create a luggage object with number of bags and weight read from the user. Note that the entered number of bags must be 2 or greater and the weight must be 40 or greater The constructor Passenger(name:String ticketNo: int) must initialize the name and ticketNo with the passed argument. It must create luggage object with default values. The toString method must be overridden to return a String that consists of the passenger name and ticketNo on one line, and the luggage toString method on the second line. Print the luggage info by invoking the getLuggage method instead of using the luggage data field since the way luggage is computed (getLuggage) is overridden for FirstClass passengers. 3. Economy: a. The no-arg constructor must invoke the super class no-arg constructor. Then ask the user if he wants a meal to be added or not, and set the mealAdded data field accordingly. b. The second constructor must pass the name and ticketNo to the super class constructor and initialize the mealAdded with the passed boolean argument. c. The toString method must be overridden to return the String of the super class toString method and add either the statement "Meal Added" or "No Meal Added to it based on the value of mealAdded on a new line. 4. FirstClass: a. The no-arg constructor must invoke the super class no-arg constructor. b. The second constructor must pass the name and ticketNo to the super class constructor. c. The extraLuggage must always be initialized with a luggage object with default values. d. Override the getLuggage method such that it returns a luggage object that consists of the summation of bags and weight in the luggage and extraLuggage data fields. No main method required

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_2

Step: 3

blur-text-image_3

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

The Controllers Toolkit

Authors: Christine H. Doxey

1st Edition

1119700647, 9781119700647

More Books

Students also viewed these Accounting questions