Created
June 8, 2018 09:22
-
-
Save spidertwin2/4730436a11fffefec6262b6699bc6c36 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.0; | |
contract hotel { | |
string public hotelName; | |
string public location; | |
uint public numRooms; | |
constructor(string name, string loc, uint r) public { | |
hotelName = name; | |
location = loc; | |
numRooms = r; | |
} | |
} | |
struct room { | |
uint capacity; | |
uint numOccupants; | |
occupied occStatus; | |
address occupier; | |
} | |
room [ ] public rooms; | |
//set as public so that we can check the capacity, | |
//number of occupants and occupancy status of any room | |
enum occupied { | |
available, occupied, cleaned | |
} | |
function addRoom (uint num) public { | |
for (uint x = 0; x < num; x++) { | |
rooms.push; | |
numRooms++; | |
} | |
} | |
function changeRoomOccupancyStatus (occupied o, uint roomNo) public { | |
if (o == occupied.available) { | |
rooms[roomNo].occupier = msg.sender; | |
rooms[roomNo].occStatus = occupied.occupied; | |
rooms[roomNo].numOccupants = rooms[roomNo].capacity; | |
} | |
else if (o == occupied.occupied) { | |
require (rooms[roomNo].occStatus != occupied.occupied); | |
} | |
else if (o == occupied.cleaned) { | |
rooms[roomNo].occStatus = occupied.available; | |
rooms[roomNo].occupier = 0; | |
rooms[roomNo].numOccupants = 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment