Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement the below classes and interface as presented in the following UML diagram the class BusTrip for which you will find the code provided below.

Implement the below classes and interface as presented in the following UML diagram the class BusTrip for which you will find the code provided below. you will need later in your code. Ticket - ticketNumber: String - ticketsCounter: int - trips: Trip[] - tripNumber: int + Ticket(maxNbTrip: int) + addTrip(t: Trip): void + reduceCost(): void + toString( ): String Interface Economical + economize(): void Trip - departureCity: String - arrivalCity: String - basicPrice: double + Trip(dc: String, ac: String, bp: double) + calculateCost(): double + toString( ): String Flight - seatClass: String + Flight( dc: String, ac: String, bp: double, seatClass: String) + toString( ): String BusTrip + BusTrip(dc: String, ac: String, bp: double) + toString( ): String A. Write the abstract class Trip as presented in the above UML. The Trip class is characterized by three data fields: a String departureCity representing the trips departure city, a String arrivalCity representing the trips arrival city and a double basicPrice representing the basic price of a trip. This class has as methods. a) A constructor that initializes all the attributes. If the input basic price is negative a default value of 50 should be assigned. b) The abstract method calculateCost(). c) The toString( ) method. B. Write the interface Economical. except For all classes implement only the getters that Page 2 of 5 C. Do not implement the class BusTrip. The code is: public class BusTrip extends Trip{ public BusTrip(String dc, String ac, double bp){ super(dc, ac, bp); } public double calculateCost(){ return getBasicPrice(); } public String toString(){ return "A bus trip departing from " + getDepartureCity() + ", going to " + getArrivalCity() + " for a basic price of " + getBasicPrice() + "$."; } } D. [10 pts] Implement the class Flight characterized by a String data field seatClass. a) A constructor that initializes all the attributes. If the input seat class was not First Class nor Economic, the value Invalid Class should be assigned. b) A toString( ) method that returns a description of the flight in the form: A flight departing from Beirut, going to Paris for a basic price of 650$. The seat class reserved for this flight is economic. c) Implement the calculateCost( ) method The cost of a flight is its basic price if the seat class is Economic and is its basic price * 2.5 if the seat class is First class. d) Implement the economize method of the Economical Interface. A flight is economized by making its seatClass as Economic. E. [20 pts] Implement the class Ticket characterized by one String data field ticketNumber, a static integer data field ticketsCounter, an array trips of Trip objects, and the integer tripNumber. The methods are: a) A constructor that increments ticketNumbers by one, create the trips array, and generates a ticket number by concatenating TN with the current ticketsCounter. The maxNbTrip parameter is used for the size of the array trips b) A method addTrip(t: Trip) that adds a trip to the set of trips of this ticket if it was possible. c) A method reduceCost() that calls the economize method on every trip that could be economized. d) A toString() method that returns a description about the ticket containing all its information and the information of its trips in the form: The ticket TN312 has the following trips: 1. A flight departing from Beirut, going to Paris for a basic price of 650$. The seat class reserved for this flight is economic. 2. A train trip departing from Paris, going to Barcelona for a basic price of 270$. It is a VIP reservation. Question 2 [20 points] Implement the driver class (application) as follows: a) Create a ticket object of maxNbTrip = 100 and add to it a first-class flight trip from Prague to Vienna for a basic price of 150$ and another bus trip from Vienna to Venice for a basic price of 92$. b) Write code to display total cost of the ticket, then reduce the cost of the ticket. c) Write code to display the total cost of the ticket, which includes the cost of all the tickets trips. d) Write code to display the number of bus trips in the ticket.

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

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

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions