Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java language Implement the below classes and interface as presented in the following UML diagram except the class BusTrip for which you will find the

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Java language

Implement the below classes and interface as presented in the following UML diagram except the class BusTrip 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 it economize(): void Ticket - ticketNumber: String ticketsCounter: int - trips: Tripl - tripNumber: int +Ticket(maxNbTrip: int) + addTrip(t: Trip): void + reduceCost(): void + toString(): String A I departureCity: String arrivalCity: String - basicPrice: double + Trip(de: String, ac String, bp. double) + calculateCost(): double + toString(): String Bus Trip Flight seatClass. String Trip - departureCity: String arrivalCity: String - basicPrice: double + Trip(de: String, ac: String. bp. double + calculateCosto: double + toString(): String ZN Bus Trip + Bus Trip(dc: String, ac: String, bp: double) + toString(: String Flight seatClass. String Flight de: String, ac: String, bp: double, seatClass: String) it toString(: Swing A. [6 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 arrivalCiw representing the trip is 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 atteibutes. If the input basic price is negative a default value of 50 should be assigned. b) The abstract method chlewareOHOL c) The abstract method roSpring B. [4 pts] Write the interface Economical, C. Do not implement the class Bus Trip. The code is: public class BusTrip extends Trip public Bus Trip(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 tickets Counter, an array trips of Trip objects, and the integer tripNumber. The methods are: a) A constructor that increments tickets Counter 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 Beint, going to Paris for a basic price of 650$. The seat cla33 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 maxNb Trip = 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 928. 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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

3319234609, 978-3319234601

More Books

Students also viewed these Databases questions