A hotel keeps records of its sales in a text file (called "hotel.txt"; provided in the MOODLE). Each line contains the following information separated by semicolons (“:"): The client's name, the service sold (such as Dining, conference...), and the amount of the sale. Figure 2 shows a few lines of input file. Write a program that reads such a file and displays the total and average amount for each service category. Knowing that there are four services (Dining, Lodging, Conference, and Parking). Display an error using the proper exception if: The file does not open/exist The format of the data in the file is incorrect (e.g. sale amount = "230;9" or "12ab") • Dividing by zero (when computing average) Make sure you close any open files even if an error occurs. ** Beniamin Baver:Dining:26 5 ***

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter13: File Input And Output
Section: Chapter Questions
Problem 10PE
icon
Related questions
Question
A hotel keeps records of its sales in a text file (called "hotel.txt"; provided in the MOODLE).
Each line contains the following information separated by semicolons (“:"): The client's name,
the service sold (such as Dining, conference...), and the amount of the sale. Figure 2 shows a
few lines of input file. Write a program that reads such a file and displays the total and average
amount for each service category. Knowing that there are four services (Dining, Lodging,
Conference, and Parking). Display an error using the proper exception if:
The file does not open/exist
The format of the data in the file is incorrect (e.g. sale amount ="230;9" or “12ab")
Dividing by zero (when computing average)
Make sure you close any open files even if an error occurs.
*************************
Benjamin Bayer:Dining:26.5
English Joyce A:Lodging:120.14
Zalaya:Lodging: 173.6
Chung-cha kim:Conference:425
Service
Total Average
*****
********
Dining
Lodging
Conference 425.0 425.00
220.8
44.16
544.0 181.35
..
Dividing by Zero, this hotel service not used
Figure 2a input file sample exe2
Figure 2b Output sample exe2
Optional:
Try to resolve the division by zero error so the output becomes as shown in figure 2c
著 菁*资*兴
Service
Total Average
*** sk
**********
Dining
Lodging
Conference 425.0 425.00
220.8
44.16
544.0 181.35
Parking
0.0
0.00
*********
****
Figure 2c Output Sample2 exe2
Transcribed Image Text:A hotel keeps records of its sales in a text file (called "hotel.txt"; provided in the MOODLE). Each line contains the following information separated by semicolons (“:"): The client's name, the service sold (such as Dining, conference...), and the amount of the sale. Figure 2 shows a few lines of input file. Write a program that reads such a file and displays the total and average amount for each service category. Knowing that there are four services (Dining, Lodging, Conference, and Parking). Display an error using the proper exception if: The file does not open/exist The format of the data in the file is incorrect (e.g. sale amount ="230;9" or “12ab") Dividing by zero (when computing average) Make sure you close any open files even if an error occurs. ************************* Benjamin Bayer:Dining:26.5 English Joyce A:Lodging:120.14 Zalaya:Lodging: 173.6 Chung-cha kim:Conference:425 Service Total Average ***** ******** Dining Lodging Conference 425.0 425.00 220.8 44.16 544.0 181.35 .. Dividing by Zero, this hotel service not used Figure 2a input file sample exe2 Figure 2b Output sample exe2 Optional: Try to resolve the division by zero error so the output becomes as shown in figure 2c 著 菁*资*兴 Service Total Average *** sk ********** Dining Lodging Conference 425.0 425.00 220.8 44.16 544.0 181.35 Parking 0.0 0.00 ********* **** Figure 2c Output Sample2 exe2
Expert Solution
steps

Step by step

Solved in 2 steps with 5 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,