Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A class named Flight has been defined. It has the following instance data items: private String airline, origin, destination; private int flightNumber; Sample data

A class named Flight has been defined. It has the following instance data items: private String airline, origin, destination; private int flightNumber; Sample data might be: Delta, LEX, MIA, 8109 meaning this is a Delta flight from the LEX airport (Lexington, KY) to the MIA airport (Miami, FL) on flight number 8109. An airline is adding Business flights and wants a child class of Flight, called BusinessFlight. This new child class should have the following fields (instance data variables). client (String) A passengers (int) ticketPrice (double) bookingCharge (double) Sample data for the new class could be: Altech, 12, 625.75, 1500.00 meaning Altech wants to charter a plane for 12 passengers with a ticket price for each passenger of $625.75, and a booking charge of $1,500.00. Which of the following program segments is the best way to create a constructor with parameters (all data from parent and child) without redundant code (without repeated code in the child that was most likely done in the parent) and with proper input valid validation for child data? public BusinessFlight(String client, int passengerCount, double ticketPrice, double bookingCharge) { super(); if (passengerCount >0) this.passengerCount = passengerCount ; else this.passengerCount = 0; if (ticketPrice > 0.0) this.ticketPrice = ticketPrice ;

Step by Step Solution

3.50 Rating (143 Votes )

There are 3 Steps involved in it

Step: 1

Code public BusinessFlightString client int passengerCount double ticketPrice double bookingCharge s... 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

Java An Introduction To Problem Solving And Programming

Authors: Walter Savitch

8th Edition

0134462033, 978-0134462035

More Books

Students also viewed these Programming questions