Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class book
- {
- constructor(_name = "",_year = 0)
- {
- this.name = _name;
- this.year = _year;
- }
- getname = function()
- {
- return this.name;
- }
- getyear = function()
- {
- return this.year;
- }
- getallinfo = function()
- {
- var allinfo = "Book Info: \n Name: " + this.name + "\n Year: " + this.year + "\n";
- }
- setname = function(_name)
- {
- this.name = _name;
- }
- setyear = function(_year)
- {
- this.year = _year;
- }
- }
- class author
- {
- constructor(_name = "",_yearofbirth = 0,_books = [])
- {
- this.name = _name;
- this.yearofbirth = _yearofbirth;
- this.books = _books;
- }
- getname = function ()
- {
- return this.name;
- }
- getyearofbirth = function()
- {
- return this.yearofbirth;
- }
- getbooks = function()
- {
- for(i =0; i< books.length;i++)
- {
- books[i].getallinfo();
- }
- }
- getallinfo = function()
- {
- let fullinfo = "Author Info: \n Name: " + this.getname() + "\n Birth Year: " + this.getyearofbirth() + "\n Books by this author: " + this.getbooks() + "\n";
- return fullinfo;
- }
- setname = function(_name)
- {
- this.name = _name;
- }
- setyearofbirth = function(_yearofbirth)
- {
- this.yearofbirth = _yearofbirth;
- }
- setbooks = function(_books)
- {
- this.books = _books;
- }
- addbook = function(_book)
- {
- this.books.push(book);
- }
- removebook = function(_book)
- {
- for(book in books)
- {
- if(book === _book)
- {
- this.books.splice(books.indexOf(book),1);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement