Description
There is a class called BorrowBook that represents the act of
borrowing a book from the library.
There are a total of 10 books in this library, and each book is
numbered from 0 to 9.
To borrow a book, create a BorrowBook object.
The argument of the Constructor indicates the number of the book
you want to borrow.
If someone has borrowed the book you want to borrow, "No. Fail"
is output when BorrowBook is created.
If the book can be borrowed, "No. Success" is output, and the
book cannot be borrowed again.
The getNumTrials method of class BorrowBook returns the total
number of attempts to borrow a book.
The getNumAvailableBooks method of class BorrowBook returns
the number of books that are available for borrowing.
Complete the program by implementing class BorrowBook to
produce the given output.
[CONDITIONS]
1) The Main class shown in the Code Template cannot be
changed.
Input
no input
Output
Sample output
3 Success
5 Success
6 Success
5 Fail
9 Success
3 Fail
How many trials? 6
How many trials? 6
How many available books? 6
How many available books? 6
template:
public class Main {
public static void main(String[] args) {
BorrowBook b1 = new BorrowBook(3);
BorrowBook b2 = new BorrowBook(5);
BorrowBook b3 = new BorrowBook(6);
BorrowBook b4 = new BorrowBook(5);
BorrowBook b5 = new BorrowBook(9);
BorrowBook b6 = new BorrowBook(3);
System.out.println("How many trials? " +
b1.getNumTrials());
System.out.println("How many trials? " +
BorrowBook.getNumTrials());
System.out.println("How many available books? " +
b5.getNumAvailableBooks());
System.out.println("How many available books? " +
BorrowBook.getNumAvailableBooks());
}
}
// your code here for class BorrowBook
plz use java
Description There is a class called BorrowBook that represents the act of borrowing a book from the library. There are
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Description There is a class called BorrowBook that represents the act of borrowing a book from the library. There are
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!