Question

In: Computer Science

Project Outcomes: Develop a python program that uses:  decision constructs  looping constructs  basic...

Project Outcomes:
Develop a python program that uses:
 decision constructs
 looping constructs
 basic operations on an list of objects (find, change, access all elements)
 more than one class and has multiple objects
Project Requirements:
1. Develop a simple Hotel program. We will have two classes, a Hotel class
representing an individual hotel and a Room class. The Hotel class will contain several
Room objects and will have several operations. We will also have a driver program to test
the Hotel class.
2. Build a Hotel class that will store information about a Hotel. It will include a name and
location. It should also include a list of class Room to hold information about each
room. It will also have a int called occupiedCnt that keeps track of how many rooms in
the hotel are occupied.
Specific Requirements for the Hotel Class:
1. The Hotel class has two constructors
1. __init__ function, will read in the hotel name and location from hard-coded
values in the tester class, such as Beach Marriot Pensacola, it will also assign
numOfRooms to zero.  numOfRooms indicates how many rooms are in the hotel.
It will create a 10 element array.

2. The Hotel will have an addRoom method that will create each room with the required
information: room number, bed type, smoking/non-smoking, and the room rate. Create at
least 5 rooms with different characteristics. Each room will also have a boolean field
called occupied attribute that will be set to false when the room is created. Don't forget
to increment the numOfRooms instance variable.  Example values for the rooms are:
101 queen s 100
102 king n 110
103 king n 88
104 twin s 100
105 queen n 99
3. The UML class diagram for the Hotel class will look like this:

Hotel

theRooms: Array Room[]
name: String
location: String
occupiedCnt: int
numOfRooms: int

def __init(self)__(String,String)
def isFull(self) : boolean
def isEmpty(self) : boolean
def addRoom(self ,roomnumber,bedtype,smoking,price)
def addReservation(self,occupantName ,smoking,
bedtype)
def cancelReservation(self,occupantName)
def findReservation(self,occupantName):
def printReservationList(self)
def getDailySales(self) :
def occupancyPercentage(self) :
Setters and getters methods for name and location.


4. isFull() – returns a boolean that is true if all the rooms in the hotel are occupied.
5. isEmpty() – returns a boolean that is true if all the rooms in the hotel are unoccupied.
6. The addReservation() method takes three parameters: the occupant’s name
(String), smoking or non-smoking request (char), and the requested bed type (String).
When this method is called, the hotel will search the list of its rooms for one that matches
the bed type and smoking/non-smoking attributes. If an unoccupied room with the correct
attributes is found, the renter's name will be set and the occupied attribute will be set
to true. In either case a message will be printed that will state whether or not the
reservation was made.
7. When the cancelReservation() method executes, the hotel will search for the
name of the visitor in each room. If it is found, the occupied attribute will be set to false.
In either case a message will state whether or not the reservation was cancelled. This
method calls the private utility method findReservation()to scan the list of rooms
looking for a guest by name. It will return the index of the room in the Array of rooms
or NOT_FOUND if the room is not found, which will be declared as:
NOT_FOUND = -1;
8. findReservation() will take in a String representing the occupant’s name and
search the occupied rooms for a reservation with that person’s name. It will return the
index of the room or NOT_FOUND if not found.
9. printReservationList() will scan through all the rooms and display all details
for only those rooms that are occupied. For example:

Room Number: 102
Occupant name: Pinto
Smoking room: n
Bed Type: king
Rate: 110.0
Room Number: 103
Occupant name: Wilson
Smoking room: n
Bed Type: king
Rate: 88.0
10. getDailySales() will scan the room list, adding up the dollar amounts of the room
rates of all occupied rooms only.
11. occupancyPercentage() will divide occupiedCnt by the total number of rooms to
provide an occupancy percentage.
12. __str__ – returns a nicely formatted string giving hotel and room details (by calling
the __str__ in the Room class) for all the rooms in the hotel. For example:
Hotel Name : Beach Marriot
Number of Rooms : 5
Number of Occupied Rooms : 1

Room Details are:

Room Number: 101
Occupant name: Not Occupied
Smoking room: s
Bed Type: queen
Rate: 100.0
Room Number: 102
Occupant name: Coffey
Smoking room: n
Bed Type: king
Rate: 110.0
Room Number: 103
Occupant name: Wilson
Smoking room: n
Bed Type: king
Rate: 88.0
Room Number: 104
Occupant name: Not Occupied

Smoking room: s
Bed Type: twin
Rate: 100.0
Room Number: 105
Occupant name: Not Occupied
Smoking room: n
Bed Type: queen
Rate: 99.0


13. The Room class diagram will look like this:

Room

roomNum: int
bedType: String
rate: double
occupantName: String
smoking: char
occupied: boolean
def __init__(int,String,char,double)
def getBedType(): String
def getSmoking(): char       
def getRoomNum(): int
def getRoomRate(): double
def getOccupant(): String
def setOccupied(boolean)
def setOccupant(String)
def setRoomNum(int)
def setBedType(String)
def setRate(double)
def setSmoking(char)
def isOccupied(): boolean

1. The __init__() for a Room takes an int (room number), String (bed type), char (s or n for
smoking or non-smoking)), and a double (room rate).
2. isOccupied() method returns true if the room is occupied, false otherwise.

3. __str__() provides all the details of a room - room number, name of guest(if
occupied) , bed type, smoking/non-smoking, rental rate. This should all be formatted
nicely with one attribute on each line using the '\n' escape character. See example above.
4. Several accessor and mutator methods for the Room class.

# Use list to store the room details.
You have to store required data in the list/database. You can store hotel name, address, and
all rooms. Customer data in database tables.

Solutions

Expert Solution

'''

Python version : 2.7

Python program to develop a simple Hotel program

'''

# Room class

class Room:

               def __init__(self,roomNum, bedType, smoking, rate):

                              self.roomNum = roomNum

                              self.bedType = bedType

                              self.smoking = smoking

                              self.rate = rate

                              self.occupantName = None

                              self.occupied = False

                             

                             

               def getBedType(self):

                              return self.bedType

                             

               def getSmoking(self):

                              return self.smoking

                             

               def getRoomNum(self):

                              return self.roomNum

                             

               def getRoomRate(self):

                              return self.rate

                             

               def getOccupant(self):

                              return self.occupantName

                             

               def setOccupied(self,occupied):

                              self.occupied = occupied

                             

               def setOccupant(self,occupantName):

                              self.occupantName = occupantName

                             

               def setRoomNum(self,roomNum):

                              self.roomNum = roomNum

                             

               def setBedType(self,bedType):

                              self.bedType = bedType

                             

               def setRate(self,rate):

                              self.rate = rate

                             

               def setSmoking(self,smoking):

                              self.smoking = smoking

                             

               def isOccupied(self):

                              return self.occupied

                             

               def __str__(self):

                              roomStr = '\nRoom Number: '+str(self.roomNum)

                              if(self.occupied and (self.occupantName != None)):

                                             roomStr += '\nOccupant Name : '+self.occupantName

                              else:

                                             roomStr += '\nOccupant Name : Not Occupied'

                              roomStr += '\nSmoking room : '+self.smoking + '\nBed Type : '+self.bedType + '\nRate : '+"{0:.1f}".format(self.rate)+'\n'

                             

                              return roomStr

                             

# Hotel class      

class Hotel:

              

               NOT_FOUND = -1

              

               def __init__(self, name, location):

                              self.name = name

                              self.location = location

                              self.numOfRooms = 0

                              self.theRooms = [None]*10

                              self.occupiedCnt = 0

               def getName(self):

                              return self.name

                             

               def getLocation(self):

                              return self.location

                             

               def setName(self,name):

                              self.name = name

                             

               def setLocation(self, location):

                              self.location = location

                             

               def isFull(self):

                              return(self.numOfRooms == self.occupiedCnt)

                             

               def isEmpty(self):

                              return(self.occupiedCnt == 0)

                             

               def addRoom(self,roomNumber, bedType, smoking, price):

                              if self.numOfRooms < len(self.theRooms):

                                             room = Room(roomNumber,bedType,smoking,price)

                                             self.theRooms[self.numOfRooms] = room

                                             self.numOfRooms += 1

                              else:

                                             print('Rooms list in the Hotel is full')

              

               def addReservation(self, occupantName, smoking, bedType):

                             

                              roomFound = False

                              for room in self.theRooms:

                                             if((room != None) and (not room.isOccupied()) and (room.getSmoking().lower() == smoking.lower()) and (room.getBedType().lower() == bedType.lower())):

                                                            room.setOccupied(True)

                                                            room.setOccupant(occupantName)

                                                            self.occupiedCnt += 1

                                                            roomFound = True         

                                                            break

                                                           

                              if(roomFound):

                                             print('Reservation finished successfully!')

                              else:

                                             print('Unable to find room with the given preferences!')

              

               def cancelReservation(self, occupantName):

                              ind = self.findReservation(occupantName)

                              if ind != self.NOT_FOUND:

                                             self.theRooms[ind].setOccupied(False)

                                             self.theRooms[ind].setOccupant(None)

                                             self.occupiedCnt -= 1

                                             print('Reservation was cancelled successfully!')

                                            

                              if ind == self.NOT_FOUND:

                                             print("Reservation doesn't exist")

                             

               def findReservation(self,occupantName):

                             

                              for i in range(self.numOfRooms):

                                            

                                             if((self.theRooms[i].isOccupied()) and (self.theRooms[i].getOccupant().lower() == occupantName.lower())):

                                                            return i

                                                           

                              return self.NOT_FOUND

               def printReservationList(self):

                             

                              for room in self.theRooms:

                                             if((room != None) and (room.isOccupied())):

                                                            print(room)

                                                           

                             

               def getDailySales(self):

                              dailySales = 0

                             

                              for room in self.theRooms:

                                             if((room != None) and (room.isOccupied())):

                                                            dailySales += room.getRoomRate()

                                                           

                              return dailySales

               def occupancyPercentage(self):

                              if self.numOfRooms > 0:

                                             return (float(self.occupiedCnt*100)/self.numOfRooms)

                              return 0

               def __str__(self):

                             

                              hotelStr = 'Hotel Name : '+self.name +'\nNumber of Rooms : '+str(self.numOfRooms) +'\nNumber of Occupied Rooms : '+str(self.occupiedCnt)

                              hotelStr += '\n\nRoom Details are :\n'

                              for i in range(self.numOfRooms):

                                             hotelStr += str(self.theRooms[i])

                             

                              return hotelStr

# function to display and get the user choice                        

def menu():

              

               print('1. Add room')

               print('2. Add Reservation')

               print('3. Cancel Reservation')

               print('4. Print Reservation List')

               print('5. Get Daily Sales')

               print('6. Get Occupancy Percentage')

               print('7. Exit')

              

               choice = int(raw_input('Enter a choice(1-7) : '))

              

               while choice < 1 or choice > 7:

                              print('Invalid choice')

                              choice = int(raw_input('Enter a choice(1-7) : '))

                             

               return choice     

# main function

def main():

              

               hotel = Hotel("Beach Marriot","NNN")

               hotel.addRoom(101,"queen","s",100)

               hotel.addRoom(102,"king","n",110)

               hotel.addRoom(103,"king","n",88)

               hotel.addRoom(104,"twin","s",100)

               hotel.addRoom(105,"queen","n",99)

              

               print(hotel)

               done = False

               while not done:

                              choice = menu()

                             

                              if choice == 1:

                                             roomNumber = int(raw_input('Room Number : '))

                                             bedType = raw_input('Bed Type : ')

                                             smoking = raw_input('Smoking(s) or Non-Smoking(n) : ')

                                             price = float(raw_input('Price : '))

                                            

                                             hotel.addRoom(roomNumber,bedType,smoking,price)

                                            

                              elif choice == 2:

                                             occupantName = raw_input('Occupant Name : ')

                                             smoking = raw_input('Smoking room(s) or Non-Smoking(n) : ')

                                             bedType = raw_input('Bed Type : ')

                                            

                                             hotel.addReservation(occupantName, smoking, bedType)

                                            

                              elif choice == 3:

                                             occupantName = raw_input('Occupant Name : ')

                                             hotel.cancelReservation(occupantName)

                                            

                              elif choice == 4:

                                             hotel.printReservationList()

                                            

                              elif choice == 5:

                                             print('Daily Sales : %.2f' %(hotel.getDailySales()))

                                            

                              elif choice == 6:

                                             print('Occupancy Percentage : %.2f' %(hotel.occupancyPercentage()))

                             

                              else:

                                             done = True

              

#call the main function  

main()   

#end of program                            

Code Screenshot:

Output:


Related Solutions

Programming Project #1: Manage Simple Expenses Objectives: • Use basic C++ constructs: if, switch, repetition (looping)...
Programming Project #1: Manage Simple Expenses Objectives: • Use basic C++ constructs: if, switch, repetition (looping) and functions • Perform simple data type and string object manipulations • Solve problem, design solution and implement using C++ Description: Write a menu-driven program named “ManageSimpleExpenses” that provides the following options: 1. Earn 2. Spend 3. Show logs 4. Exit Basically, the program allows the user to enter earning or spending amounts and keep track of the current balance. It also print out...
TheMathGame Develop a program in PYTHON that will teach children the basic math facts of addition....
TheMathGame Develop a program in PYTHON that will teach children the basic math facts of addition. The program generates random math problems for students to answer. User statistics need to be kept in RAM as the user is playing the game and recorded in a text file so that they may be loaded back into the program when the student returns to play the game again. In addition, the youngster should be allowed to see how (s)he is doing at...
Java Proect Project Outcomes Develop a Java program that: • creates a user designed class •...
Java Proect Project Outcomes Develop a Java program that: • creates a user designed class • uses proper design techniques including reading UML Class Diagrams • reads input from the keyboard using a Scanner Object and its methods • uses selection (if and if else) statements • uses iteration (while, do while or for) statements • uses String comparison methods. • follows standard acceptable programming practices. • handles integer overflow errors Prep Readings: Zybooks chapter 1 - 6 1. General...
For this project: Create a game with at least 3 outcomes Develop a probability table with...
For this project: Create a game with at least 3 outcomes Develop a probability table with the outcomes for X and the probability p(X) Find the expected value and standard deviation Determine if your game is fair How could be changed to make it fair or favor the player or "house"? Run the game 50 times and record each outcome Compute the empirical probability and compare it against the theoretical probability in #2. Find the average outcome of the 50...
Develop a python program to - Create a 2D 10x10 numpy array and fill it with...
Develop a python program to - Create a 2D 10x10 numpy array and fill it with the random numbers between 1 and 9 (including 0 and 9). - Assume that you are located at (0,0) (upper-left corner) and want to move to (9,9) (lower-right corner) step by step. In each step, you can only move right or down in the array. - Develop a function to simulate random movement from (0,0) to (9,9) and return sum of all cell values...
You are asking to develop a “Triangle Guessing” game in Python for the assignment. The program...
You are asking to develop a “Triangle Guessing” game in Python for the assignment. The program accepts the lengths of three (3) sides of a triangle as input from a player. The program output should indicate whether the triangle is a right triangle, an acute triangle, or an obtuse triangle. 1.Tips to help you for this assignment: Make sure each side of the triangle is a positive integer. Use try/except for none positive integer input. 2. Validating the triangle. That...
Answer as soon as possible!!! Code must be done with Python Develop a basic File Transfer...
Answer as soon as possible!!! Code must be done with Python Develop a basic File Transfer Protocol (FTP) application that transmits files between a client and a server using Python. Your programs should implement four FTP commands: (1) change directory (cd), (2) list directory content (ls), (3) copy a file from client to a server (put) and (4) copy a file from a server to a client (get). Implement two versions of the program: one that uses stock TCP for...
write a python program, please. Create a program that uses the Gettysburg Address as input and...
write a python program, please. Create a program that uses the Gettysburg Address as input and outputs a list of tuples for every two words. For example: [('Four', 'score'),('and', 'seven'), ...].
Develop a python program to create a quiz with limited time and attempts!!! Add comments and...
Develop a python program to create a quiz with limited time and attempts!!! Add comments and screenshot of running the program quiz could be of anything like , what's the sum of 2&2. There should be number of attempts(limited) suppose if the answer is wrong.
Develop a program using python to demonstrate data exchange using USB protocol.
Develop a program using python to demonstrate data exchange using USB protocol.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT