Question: 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
Code public BusinessFlightString client int passengerCount double ticketPrice double bookingCharge s... View full answer
Get step-by-step solutions from verified subject matter experts
