Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programs need to be written in the Java language Question 1. Context : You will write a program for a travel agency that you will

Programs need to be written in the Java language

Question 1.

Context: You will write a program for a travel agency that you will extend in the following exercises. In this program, you will have a Service class, a FlightService class and a HotelService class. The Service class contains common information all services of the travel agency have. The FlightService and HotelService classes inherit from the Service class, and they represent specific services the company offers.

In this exercise, you need to:

Declare the class Service. This will be the parent class. The services will have:

A protected attribute price that is a decimal number representing the price of the service. It's received in the constructor of the class.

Write a public method called printTicket, that does not receive any parameters and it doesn't return anything. This method will print the following message:

*** TICKET FOR SERVICE ***

Price: $Y

************************************

Where Y the base price for that service.

Write a class HotelService, that inherits from the Service class. The hotel services will:

Have a constructor that receives the price and calls the constructor of the parent class.

You will NOT create an attribute in this class.

Override the method printTicket. In this class, the method will print the following message:

*** HOTEL TICKET ***

Price per room: $Y

************************************

Y is the price.

Write a class FlightService, that inherits from the Service class. The airplane flight service will:

Have a constructor that receives the price, and calls the constructor of the parent class.

You will NOT create an attribute in this class.

Override the method printTicket. In this class, the method will print the following message:

*** AIRPLANE TICKET ***

Price for the ticket: $Y

************************************

Y is the base price.

Write a Test java class. In this class you only need a main method to test the previous classes. In this main method, you have to:

Create a Service object, with a price of $50.00. Call the printTicket method on this object.

Create a HotelService object, with a price of $50.00. Call the printTicket method on this object.

Create a FlightService object, with a price of $50.00. Call the printTicket method on this object.

Context: You will extend the program you wrote for exercise 1. Now, your flight and hotel services will have an additional piece of information to add to their corresponding tickets.

You need to:

Modify your FlightService class, so that now:

It has a constant double attribute called tax, which is always equal to 0.1. This represents the tax to be applied to the service.

Create a new method called getTotalPrice, that doesn't receive any parameter and returns a double. It computes the total price the following way: price * (1 + tax)

Update the printTicket method, so that now it prints the following:

*** AIRPLANE TICKETS INFORMATION ***

Price per ticket: $Y

Total price: $Z

************************************

Y is still the price, and Z is the total price after the tax has been added (call the getTotalPrice method to obtain this number)

Modify your HotelService class, so that now:

It has a String attribute called hotelCompany, which represents the name of the hotel company for that service.

You need to update the constructor, so that now it also receives the String hotel company name.

Update the printTicket method, so that now it prints the following:

*** HOTEL TICKET ***

Price: $Y

Hotel company: M

************************************

M is the name of the hotel company, and Y is the price.

Use the class Test you wrote before to test your classes again.

Context: you will extend the program you wrote for the previous exercise, to work with exceptions and basic file I/O.

You need to:

Create a prices.txt file with two double values in two different lines. That is, the context should be something like:

25.50

75.95

Create a text file called hotel.txt that will contain the name of a hotel company. i.e. Hilton Hotel

Modify the printTicket from all three classes so that, instead of printing that message, it returns it. That is, your method now returns the String with the message (Hint: To keep the different lines, add the escape character ).

Modify your Test java class, so that:

In your main method, you are going to create :

One HotelService object. The price will be the first number in the prices.txt file. The name of the hotel company is the value in the hotel.txt file.

One FlightService object. The price will be the second number in the prices.txt file.

IMPORTANT: You need to read the values from the text files. You cannot hard code them in your program.

After you have created the objects, call the printTicket and save the results in two files: airlineTicket.txt, and hotelTicket.txt

Check and handle the following exception:

The exception thrown when a file you want to read or write does not exist.

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

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions