Objectives To solve problems using ArrayLists To perform file I/O Introduction Instructions and Information There...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Objectives To solve problems using ArrayLists ● To perform file I/O Introduction Instructions and Information There will be two classes implemented for this assignment: Hotel O HotelDemo Contains the data and some business logic related to an individual hotel O O Contains the main method Do not use the newer Java features for "unnamed classes" (with implicit class declarations) or instance main methods For this assignment, you will implement a class named Hotel. The class should contain: Data fields A private int data field named numRooms representing the total number of rooms available for the given Hotel A private int data field named numOccupied, representing the number of rooms currently occupied A private String data field named hotelName, with the name of the hotel Methods A no-arg constructor that creates a Hotel object with the name "Default Hotel", and 10 rooms total along with 0 rooms occupied A constructor that creates a Hotel object based on three parameters: hotelName, num Rooms, and numOccupied O These parameters correspond to the fields O The fields should be set to the corresponding parameter values Accessor (getter) and mutator (setter) methods for all data fields ● Input ● ● A getOccupancyRate method that returns the occupancy rate for the hotel O Occupancy rate = number of rooms occupied / total number of rooms The input will be obtained from a file, named input.txt. Each line will contain either one or three values. Each line represents a separate Hotel, whose data should be made into an object. If there's one value (meaning anything that doesn't have any commas in it - could be a string, integer, double, etc.), you just create a Hotel object using the no-arg constructor. If there are three values provided, you create a Hotel object, with the following conditions: O When you eventually display the value, you should display up to two decimal places Hint: The DecimalFormat class or using printf could help with this ■ Number of rooms must be at least 5 Number of occupied rooms cannot exceed the number of available rooms O If it does in fact do this for a given line, you should not create a Hotel object or add its reference to the ArrayList (see below) Regardless, if the input is a valid hotel, you should create the Hotel object and add the object's reference to an ArrayList of Hotel objects, maintained in the same file as main. Input Format If one value: Hints If three values: <some value, a number of string, no commas> Name, Number of rooms, Number of occupied rooms Specifically, a single line of example input might be: Billy Bob's Inn, 15, 5 Consider that the nextLine method of a Scanner can be used to read in the entire line of data as a String The String class has a method called split that will return a String array, with values separated by a delimiter O Default delimiter is space, but this can be changed Output As soon as the file is read into memory and the data is placed in the appropriate data structure(s), the following will be printed to standard output (the console), in general form: 2 <Hotel Name> : <occupancy rate> At the very bottom of the output, you should display the overall occupancy rate across all hotels that were read in from file (only count the valid ones, of course). Total occupancy: Example Sample Input File Bob's Hotel, 15, 5 0 <occupancy rate> John's Hotel, 20, 5 Hotel California, 100, 80 Snugglebear 66, 50, 50 Dumptruck Inn, 50, 100 (Note that line 2 should be default because there aren't three values, and the last line is invalid because the occupants outnumber the total number of rooms) Sample Output Note: Display the values as a percentage Bob's Hotel: 33.00% Default Hotel: 0.00% John's Hotel: 25.00% Hotel California: 80.00% Snugglebear 66: 100% Total occupancy: 71.79% (Total occupancy was calculated by summing all the total occupancy at each hotel, and the total available rooms, and then dividing number of occupied rooms by total number of rooms at each hotel - it only considered the valid hotels. So, this was 140/195). The default hotel had 10 rooms. Deliverables To turn in the assignment, please upload a zip file of a folder containing the .java files necessary for the program to run, as well as screenshots of your program running. Upload the zip file to to the appropriate assignment directory on Canvas. 3 Objectives To solve problems using ArrayLists ● To perform file I/O Introduction Instructions and Information There will be two classes implemented for this assignment: Hotel O HotelDemo Contains the data and some business logic related to an individual hotel O O Contains the main method Do not use the newer Java features for "unnamed classes" (with implicit class declarations) or instance main methods For this assignment, you will implement a class named Hotel. The class should contain: Data fields A private int data field named numRooms representing the total number of rooms available for the given Hotel A private int data field named numOccupied, representing the number of rooms currently occupied A private String data field named hotelName, with the name of the hotel Methods A no-arg constructor that creates a Hotel object with the name "Default Hotel", and 10 rooms total along with 0 rooms occupied A constructor that creates a Hotel object based on three parameters: hotelName, num Rooms, and numOccupied O These parameters correspond to the fields O The fields should be set to the corresponding parameter values Accessor (getter) and mutator (setter) methods for all data fields ● Input ● ● A getOccupancyRate method that returns the occupancy rate for the hotel O Occupancy rate = number of rooms occupied / total number of rooms The input will be obtained from a file, named input.txt. Each line will contain either one or three values. Each line represents a separate Hotel, whose data should be made into an object. If there's one value (meaning anything that doesn't have any commas in it - could be a string, integer, double, etc.), you just create a Hotel object using the no-arg constructor. If there are three values provided, you create a Hotel object, with the following conditions: O When you eventually display the value, you should display up to two decimal places Hint: The DecimalFormat class or using printf could help with this ■ Number of rooms must be at least 5 Number of occupied rooms cannot exceed the number of available rooms O If it does in fact do this for a given line, you should not create a Hotel object or add its reference to the ArrayList (see below) Regardless, if the input is a valid hotel, you should create the Hotel object and add the object's reference to an ArrayList of Hotel objects, maintained in the same file as main. Input Format If one value: Hints If three values: <some value, a number of string, no commas> Name, Number of rooms, Number of occupied rooms Specifically, a single line of example input might be: Billy Bob's Inn, 15, 5 Consider that the nextLine method of a Scanner can be used to read in the entire line of data as a String The String class has a method called split that will return a String array, with values separated by a delimiter O Default delimiter is space, but this can be changed Output As soon as the file is read into memory and the data is placed in the appropriate data structure(s), the following will be printed to standard output (the console), in general form: 2 <Hotel Name> : <occupancy rate> At the very bottom of the output, you should display the overall occupancy rate across all hotels that were read in from file (only count the valid ones, of course). Total occupancy: Example Sample Input File Bob's Hotel, 15, 5 0 <occupancy rate> John's Hotel, 20, 5 Hotel California, 100, 80 Snugglebear 66, 50, 50 Dumptruck Inn, 50, 100 (Note that line 2 should be default because there aren't three values, and the last line is invalid because the occupants outnumber the total number of rooms) Sample Output Note: Display the values as a percentage Bob's Hotel: 33.00% Default Hotel: 0.00% John's Hotel: 25.00% Hotel California: 80.00% Snugglebear 66: 100% Total occupancy: 71.79% (Total occupancy was calculated by summing all the total occupancy at each hotel, and the total available rooms, and then dividing number of occupied rooms by total number of rooms at each hotel - it only considered the valid hotels. So, this was 140/195). The default hotel had 10 rooms. Deliverables To turn in the assignment, please upload a zip file of a folder containing the .java files necessary for the program to run, as well as screenshots of your program running. Upload the zip file to to the appropriate assignment directory on Canvas. 3
Expert Answer:
Answer rating: 100% (QA)
Based on the given assignment instructions youll need to create a Java program with two classes Hotel and HotelDemo Lets first outline what each class will need according to your assignment brief The ... View the full answer
Related Book For
Accounting Information Systems
ISBN: 9780132871938
11th Edition
Authors: George H. Bodnar, William S. Hopwood
Posted Date:
Students also viewed these programming questions
-
A bank has two clients who are both importing goods from the same foreign supplier. The first client is importing goods worth $10 million and is paying for the goods in 90 days. The second client is...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
What is the capacity for each of the containers in Problems 4754? (Give answers in the U.S. system to the nearest tenth of a gallon or in metric to the nearest tenth of a liter.) Orange 25 cm Juice...
-
A hand-held electric mixer contains an electric motor. Model the motor as a single flat compact circular coil carrying electric current in a region where a magnetic field is produced by an external...
-
What is the purpose of the social security tax?
-
North Shore Childcare Ltd plans to open a day care centre at the beginning of next year. A building has been leased and the company has estimated that the following annual costs will be required....
-
On January 1, 2004, Pre Corporation acquired 60 percent of the voting common shares of Sue Corporation at an excess of fair value over book value of $1,000,000. This excess was attributed to plant...
-
As you lead your organization's performance management efforts, your chief human resources officer has real concerns about the buy-in among your staff. She has come to you to share her thoughts. With...
-
How do you calculate the percentage of change in sales from 20X8 to 20X9? This will go in cell D7? Show the formula. Kretsmart Common-Size Income Statements For the Years Ended December 31, 20'X'9,...
-
Consider a CMOS process for which Lmin = 0.8 m, tox= 15 nm, ,,= 550 cm/V-s, and V = 0.7 V. V, (a) Find Cox and kn. (b) For an NMOS transistor with W/L = 16 um/0.8 m, calcu- late the values of Vov,...
-
The book talks about the different leadership styles and the differences in leadership approaches across cultures/countries. provide a discussion of two different leadership styles and provide an...
-
Suppose you borrow $10,000 through a student loan program at an interest rate of 4% compound annual interest. The payments are deferred for four years, after which you must make six equal annual...
-
The new acquisition we are planning. It's a big secret, but I'm a good listener! Our stock should skyrocket and I need the money. Do you think that if I get my wife to buy stock now I'll get in...
-
Compare the traditional understanding of separation of powers with the new version or invention described and defended in The Federalist.
-
Why is scarcity not simply a result of the fall of Adam (i.e., sin)?
-
Seths father is thinking of buying his son a six-month movie pass for $40. With the pass, matinees cost $1.00. If matinees are normally $3.50 each, how many times must Seth attend in order for it to...
-
The Ferris wheel in the figure has a radius of 68 feet. The clearance between the wheel and the ground is 14 feet. The rectangular coordinate system shown has its origin on the ground directly below...
-
Identify an inquiry for (i) a specific record and (ii) a group of related records that might be made for each of the following files. Discuss how these inquiries might be satisfied if the file...
-
The flowchart in Figure 8.13 depicts the activities relating to the shipping, billing, and collecting processes used by Pitts-burgh Wood, Inc. Required Identify weaknesses in the system of internal...
-
The process of creating customer master records in SAP ERP is complex but results in information that is useful in the sales business process. However, the process of creating customer master records...
-
A prototype can be ___________. (a) Complete system with partial requirements (b) Working model (c) Full-fledged system (d) All of these
-
_____________ is also used as requirement finding and feasibility testing tool. (a) Prototype (b) Reports (c) System (d) Procedure
-
Which of the following systems development approach is adopted if information requirements are not well defined? (a) SDLC (b) Prototype (c) Structured approach (d) Agile
Study smarter with the SolutionInn App