//Write your own contracts here. Currently compiles using solc v0.4.15+commit.bbb8e64f. pragma solidity ^0.4.25; contract SimpleLibrarySystem { // data needed uint totalNumberOfBooks; uint totalNumberOfBorrowers; uint currentNumberOfBorrowers; struct bookDetails { uint id; string titleOfBook; string authorOfBook; bool isBorrowed; } struct borrowerDetails { uint id; uint bookID; string borrowerName; } // call just once constructor() public { totalNumberOfBooks = 0; totalNumberOfBorrowers = 0; currentNumberOfBorrowers = 0; } mapping (uint => bookDetails) books; mapping (uint => borrowerDetails) borrowers; function addBooks(string title, string author) public { totalNumberOfBooks+=1; books[totalNumberOfBooks] = bookDetails(totalNumberOfBooks, title, author, false); } function borrowBook(uint bookID, string name) public { require(books[bookID].isBorrowed == false); totalNumberOfBorrowers+=1; currentNumberOfBorrowers+=1; borrowers[totalNumberOfBorrowers] = borrowerDetails(totalNumberOfBorrowers, bookID, name); books[bookID].isBorrowed = true; } function returnBook(uint bookID) public { require(books[bookID].isBorrowed == true); currentNumberOfBorrowers-=1; books[bookID].isBorrowed = false; } function getTotalNumberOfBooks() public constant returns (uint) { return totalNumberOfBooks; } function getCurrentNumberOfBorrowers() public constant returns (uint) { return currentNumberOfBorrowers; } }
0.4.25