Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I want the answer in java please. Implement the below classes and interface as presented in the following UML diagram except the class Bus Trip

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
I want the answer in java please.
Implement the below classes and interface as presented in the following UML diagram except the class Bus Trip for which you will find the code provided below. For all classes implement only the getters that you will need later in your code. "Interface" Economical Ticket - ticketNumber: String - ticketsCounter: int - trips: Trip[] - tripNumber: int + Ticket(maxNbTrip: int) + addTrip(t: Trip): void + reduceCost(): void + toString(): String + economize(): void A Trip - departureCity: String - arrivalCity: String - basicPrice: double + Trip(de: String, ac: String, bp: double) + calculateCost(): double + toString(): String A Bus Trip + Bus Trip(de: String, ac: String, bp: double) + toString(): String Flight - seatClass: String + Flight de: String, ac: String, bp: double, seatClass: String) + toString(): String Trip - departureCity: String arrivalCity: String basicPrice: double + Trip(de: String, ac: String, bp: double) + calculateCost(): double + toString(): String 4 Bus Trip + Bus Trip(de: String, ac: String, bp: double) + toString(): String Flight seatClass: String + Flight de: String, ac: String, bp: double, seatClass: String) + toString(): String A. 16 pts) 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 trip's departure city, a String arrivalCity representing the trip's 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. 14 pts Write the interface Economical C. Do not implement the class Bus Trip. The code is: public class BusTrip extends Trip! public BusTrip (String de, String ac, double bp) { super (de, ac, bp); } public double calculateCosto return get BasicPrice(); 1 public String toString() { return "A bus trip departing from " + get DepartureCity() + ", going to getArrivalCity() + " for a basic price of " + get BasicPrice () + "."; 1 D. [10 pts) Implement the class Flight characterized by a String data field searClass. a) A constructor that initializes all the attributes. If the input seat class was not "First Class" nor "Economie". 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 6509. 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 addTript: 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 1505 and another bus trip from Vienna to Venice for a basic price of 925. 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 ticket's 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

More Books

Students also viewed these Databases questions