Skip to content

Instantly share code, notes, and snippets.

@spidertwin2
Created June 8, 2018 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spidertwin2/4730436a11fffefec6262b6699bc6c36 to your computer and use it in GitHub Desktop.
Save spidertwin2/4730436a11fffefec6262b6699bc6c36 to your computer and use it in GitHub Desktop.
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