0% found this document useful (0 votes)
14 views3 pages

Cis296 Proj1 Fa24

The document outlines the requirements for Programming Project #1 in CIS 296 at the University of Michigan - Dearborn, focusing on implementing two classes: Hotel and HotelDemo. The Hotel class must manage data related to hotel occupancy, including constructors, accessors, and a method to calculate occupancy rates, while the HotelDemo class handles file I/O. Students are required to read hotel data from an input file, validate it, and display individual and total occupancy rates in a specified format.

Uploaded by

Fatima Tohfe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Cis296 Proj1 Fa24

The document outlines the requirements for Programming Project #1 in CIS 296 at the University of Michigan - Dearborn, focusing on implementing two classes: Hotel and HotelDemo. The Hotel class must manage data related to hotel occupancy, including constructors, accessors, and a method to calculate occupancy rates, while the HotelDemo class handles file I/O. Students are required to read hotel data from an input file, validate it, and display individual and total occupancy rates in a specified format.

Uploaded by

Fatima Tohfe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Programming Project #1

CIS 296 – John P. Baugh, Ph.D.


University of Michigan - Dearborn

Points: ________ / 100

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 Contains the data and some business logic related to an individual hotel
• HotelDemo
o Contains the main method
o 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, numRooms,
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

1
• A getOccupancyRate method that returns the occupancy rate for the hotel
o Occupancy rate = number of rooms occupied / total number of rooms
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

Input

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:

• 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:

<some value, a number of string, no commas>

If three values:

Name, Number of rooms, Number of occupied rooms

Specifically, a single line of example input might be:

Billy Bob’s Inn, 15, 5

Hints
• 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 : <occupancy rate>

Example

Sample Input File


Bob’s Hotel, 15, 50
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.

You might also like