Create a Book class. Instance variables: author title book_id :: string :: strin
ID: 3573500 • Letter: C
Question
Create a Book class.
Instance variables:
author
title
book_id
:: string :: string :: int
Methods:
__init__(self, author, title, book_id) :: constructor; instantiates all instance variables.
__str__(self) :: returns string representation with this format (including internal double-quotes and all punctuation; note, the single-quotes in the example are just our quote boundaries! The first character in this example string is B): 'Book("Dr. Seuss", "The Cat in the Hat", 12345)'
__repr__(self) :: returns same string representation as __str__.
__eq__(self, other) :: determines if this book itself is equivalent to the other book by checking if
all three instance variables are the same. Returns a bool.
can still write functions, separately from classes, and they can have parameters that will refer to objects of our own classes we've just made. Implement these functions, outside of all class definitions. Notice that we could have chosen to make these into more methods. There's always a choice here, and honestly they might have been better as extra methods, but we wanted to show that functions can use these classes, too.
def display_loanables(library): Inspect a library's list of books that are currently at the library; create a string that, when printed, has "available: " as the first line, and the str() representation of each book (in the order as stored in the library) on the following lines. See the examples and test cases for further clarifications as needed.
def review_checked_out_list(library, patron_id): find the given patron in the library, and display their currently checked out books. Return a string that, when printed, has a first line of "George: " (use their actual name), and all following lines are their currently checked out books' str() representations. See the examples and test cases for further clarifications as needed. When the patron isn't present, just return a string like "Patron #12345 not found" instead, and don't let the program crash.
ERROR test display loanables_2 main AllTests Traceback (most recent call last): File "tester6. py", line 940, in test display loanables_2 self. assertEqual (display_loanables (lib), available: n") File "/Users/CiBe/Documents/student.py", line 8, in display loanables print (s library) TypeError: Can't conver Library object to str implicitly ERROR test review checked out-list-1 main. AllTests Trace back (m recent call last ost line 952, in test review checked out list 1. File tester 6. py", Belle: An Book Brothers Grimm "Sleeping Beauty", 3)NnBook "folk tale", "Aladdin", 5) """) self assert Equal review checked out list lib, 19 File "/Users/CiBe/Documents/student. py", line 11, in review checked out list for patron in library: TypeError: Library object is not iterable ERROR test review checked out list 2 main AllTests Traceback (most recent call last): File "tester6.py", line 959, in test review checked out list 2 self. assertEqual(review checked out list (lib,20), Beast: Vn""") File "/Users/CiBe/Documents/student py line 11, in review checked out list for patron in library Type Error: Library' object is not iterable ERROR: test review checked out list 3 main .AllTests) Trace back (m recent call last ost File ''tester6. py", line 966 in test review checked out list 3 self assertEqual(review checked out_list(lib, 100), "Patron #100 not found File "/Users/CiBe/Documents/student, py", line 11, in review checked out list for patron in library: TypeError: Library object is not iterable ERROR test return book 5 main AllTests checks that Patron can return book and update the patron's a borroweds list. relies upon Library's reshelve book Traceback (most recent call last): File "tester6. py", line 174, in test return. book 5Explanation / Answer
import java.util.*:
class Book
{
String bauthor[] = new array[100];
string btitle[] = new array[100];
int bookid[] = new array[100];
book(String author[ ] , string title[ ], int book_id[ ] )
{
string bauthor[ ]=author [ ] ;
string btitle[ ]=title[ ];
string bookid[ ]=book_id[ ];
}
bool equalsof( String author[ ], string title[ ],int book_id [ ])
{
for(int i=0;int i<author.size(); i++)
if(bauthor[i].equals(author[i]))
{
if(btitle[i].equals(title[i]))
{
if(bookid[i].equals(book_id[i]))
{
System.out.println( bauthor[i] +btitle[i]+book_id[i]);
}
}
}
else{
System.out.println("/n book not found");
}
}
String display_loanables(string librarylist [])
{
string librarylist1[ ] = new array[ ];
librarylist1[ ] = librarylist[ ];
if(librarylist1.equals(librarylist[])
{
System.out.println("availaible/n");
}
}
}
string review_checked_out_list(string librarylist[ ] , int patron_id)
{
if(patron_id == book_id)
{
system.out.println("book found);
}
else
{
system.out.println("patron #12345 not found");
}
}
class lib{
public static void main(string[] args)
{
book obj = new obj();
string author[] = new array[100];;
string title[] = new array[100];;
int book_id = new array[100];;
System.out.println("enter author");
for(i=0;i<strlen(author[i]);i++)
{
author[i]=;author[i];
}
system.out.println("enter title");
for(i=0;i<strlen(title[i]);i++)
{
title[i]=;title[i];
}
system.out.println("enter bookid");
for(i=0;i<strlen(book_id[i]);i++)
{
book_id[i]=;book_id[i];
}
librarylist [ ] =new array[ ];
System.out.println("enter items in library");
for(int i=o;i<len(librarylist[]);i++)
{
librarylist[i] = librarylist[i];
}
int patron_id[ ]=new array[ ];
for(int i=0;i<len(patron_id);i++)
{
patron_id[i]=patron_id[i];
}
obj.display_loanables(string librarylist []);
obj.review_checked_out_list(string librarylist[ ] , int patron_id);
obj.equalsof( String author[ ], string title[ ],int book_id [ ]);
}
}