Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java: asap please Question 1 [40 pts) Implement the below classes and interface as presented in the following UML diagram except the class BusTrip for

java: image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
asap please
Question 1 [40 pts) 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. Ticket -ticketNumber: String "Interface" - tickets Counter int Economical - trips. Trip - tripNumber: int + economize(): vold +Ticket(maxNbTrip: int) A + addTript Trip): void + reduce Cost(); void +toString(): String + Trip - departureCity: String - arrivalCity: String - basicPrice: double + Trip(do: String, ac: String, bp: double) + calculateCosto: double t ToString(): String BusTrip Flight seatClass: String + Bus Tripde: String, ac: String, bp: + Flight de: String, ac: String, bp: double) double, seatClass: String) +toString(): String + toString(): String 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 departure City representing the trip's departure city, a String arrhal City representing the trip's arrival city and a double baste Price representing the basic price of a trip. This class has as methods. a) A constructor that initiatives all the attributes. If the input basic price is negative a default value of 50 should be assigned b) The abstract method calculateCosif). ) The toString() method. B. 14 pts) Write the interface Economical C. Do not implement the class BasTrip. The code is: public class Bustrip extends Trip! public BusTrip (String de, String ac, double bp) { super (dc, ac, bp): ) public double calculateCosto return getBasicPrice(): ) public String toString() { return "A bus trip departing from " + getDepartureCity() + ", going to getarrivelCity() for a basic price of " + get BasicPrice () + "$.", 1 D. 110 pts Implement the class Flight characterized by 1 String dein field seasClass, #) A constructor that initializes all the attributes. If the input seat class was not "First Clasis" 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 6508. The seat class reserved Dor this flight is economie. c) Implement the calculateCost() method The cost of a flight is its basic price if the scat 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 Interfaco. A flight is economized by making its sentClass as "Economie" E. 120 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: u) A constructor that increments ticketNumbers by one, create the trips array, and generates a ticket number by concatenating TN with the current tickersCounter. The maxNbTrip puumeter is used for the size of the amay 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 loString mothod that returns a description about the ticket containing all its information and the information of its trips in the form: The ticket TX312 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 economie. 2. A train teip departing from Paris, going to Berchlona for 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 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. Dan las Question 1 (20 points] Implement the class Country only. The code of the classes Road, Street and Freeway is provided below. Country - name: String - roads: ArrayList Road -speed Limit: int + Country(name: String) - length; int + getName(): String - carpool: boolean -getRoads(): ArrayList + Road(-All Parameters. + addRoadir. Road): void ) + countStreets(): int + setters/getters + searchForStreetf(streetName: String): +toString(): String Street + toString(): String Street Freeway -name: String -code: Int A. Implement the class + Street ---All Parameters) + Freewayl-All Parameters-country. Write the following + setter/getter ) methods: + toString(): String + setter/getter A constructor to initialize + toString(): String the name and create the arrayList roads. b) The methods getName() and getRoads(). e) The coutStreets method that retums the number of streets in the array list d) The searchForStreetmethod that takes as paraneter the name of a street and returns the street object if found or pull if not found. e) A toString method to return information about all data fields. B. The Road class is cluaracterized by an int speed Limit, a int length, and a boolean carpool. The code is below: public class Road private int speedlimit, Length: private boolean carpool. publie Road int speel.imit, int length, boolean carpoal) this.apeedlimit - speedlimit: this.length -length, this.carpool - carpooli 1 //Setters and getters are all typed beze. At they stist it you need any of the public String toString() { return "Road length length, speed limit is speeds.it and carpool lane is carpool ? "available. not available.-1; 1 C. The Street class inherits from the class Road. The code is below: public class Street extends Road { private String name; public Street(String name, int speedLimit, int length, boolean carpool) super (speedlimit, length, carpool); this.name = name; public String getName() { return name; ) public void setName (String name) this.name - name: 1 goverride public String toString() { return "This 18 " + name + " st." + super.toString(); 1 D. The Freeway class inherits from the class Road. The code is below: public clase Freeway extende Road private int code; public Freeway (int coda, int speedlimit, int length, boolean carpool) super (apoodtimit, length, carpool), this.code - code: public int getCode () return code: 1 public void setCode(int code) ( this.code - code: Boverrido publie string tostring() { ceturn "This is freeway " + code + super.toString(); Question 2 [20 points] Write a client class (application) in which you: a) Create a country object with name read from the user, and add to the country object some freeways and streets as many as the user wunts. b) Write code to display the number of streets in the country object. c) Write codo display the information the country object. d) Test the searchForStreet method by reading a street name from the user and displaying its description if it is available

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

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago