Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need the answer in java please. Thank you. Implement the below classes and interface as presented in the following UML diagram except the class
I need the answer in java please. Thank you.
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. Ticket - ticketNumber: String "Interface" - ticketsCounter, int Economical - trips: Tripli + economize(); void - tripNumber: int A + Ticket(maxNbTrip: int) + add Tript: Trip): void + reduceCost(); void + toString(): String Trip - departureCity: String - arrivalCity: String - basicPrice: double + Trip(de: String, ac: String, bp: double) + calculateCosto): double + toString(): String A Bus Trip Flight + BusTrip(de: String, ac: String, bp: - seatClass: String double) + Flight de: String, ac: String, bp: + toString(): String 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 Bus Trip extends Tripi public Bus Trip (string de, String ac, double bp) { super (de, ac, bp); public double calculateCost) return getBasicPrice (); > public String toString() return "A bus trip departing from " + get DepartureCity +", going to getarrivalcity0 + " for a basic price of " + getBasicPrice () + "$."; D. 110 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 "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 6505. 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 trip Number. 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 reduceCast 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 baste price of 6505. The seat clasa reserved for this flight is economic. 2. A train trap departing from Paris, going to Barcelona for a basic price of 2705. 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 1508 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started