Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

available _ copies: int book _ copies: int total _ available _ books: static int Book ( title : String, author : String, book _

available_copies: int
book_copies: int
total_available_books: static int
Book( title : String, author : String, book_copies : int )
borrow_book (): void
return_book (): void
set_author(String author): void
get_title (): String
get_author (): String
get_available_copies () : int
get_book_copies () : int
get_borrowed_copies (): int
Attributes:
title: String (Title of the book)
author: String (Author of the book)
available_copies: int (Number of available copies of the book in the library, including only the unborrowed book)
book_copies: int (Number of copies of the book in the library or with borrowers, including the borrowed and unborrowed book)
total_available_books: static int (Number of all the currently available copies of unborrowed books)
Methods:
Book(title: String, author: String, book_copies: int): Constructor that initializes the book's title, author, and the total number of copies. It should set the available copies initially to the same as total copies. This method should update the static variable: total_available_books.
borrow_book(): Decrements the available_copies by 1 when a book is borrowed. This method should update the static variable: total_available_books.
return_book(): Increments the available_copies by 1 when a book is returned. This method should update the static variable: total_available_books.
set_author(author: String): sets the author's name of the book.
get_title(): Returns the title of the book.
get_author(): Returns the author of the book.
get_available_copies(): Returns the number of available copies.
get_book_copies(): Returns the total number of copies (including borrowed and unborrowed).
get_borrowed_copies(): Returns the number of borrowed copies.
1- In Book Class, Write the code for the constructor described in the methods list
Book(title: String, author: String, book_copies: int): Constructor that initializes the book's title, author, and the total number of copies. It should also set the available copies initially to the same value as the total copies. This method should also update the static variable: total_available_books by adding the book_copies to it.
2- In Book Class, Write the code for the method get_borrowed_copies
3- In Book Class, Write the code for the method borrow: The method decrements the available_copies by 1 if it is greater than 0. This method should also update the static variable: total_available_books after borrowing one book [1.5 pt].
4- In the Main Class
a.[1 pt] Create 2 Book objects as the following:
\table[[title,author,book_copies],[Intro to Java,Ahmed Khalid,10],[Data Structure,Tom John,8]]
b.[1 pt] Borrow 2 books from the first book "Into to Java".
c.[1 pt] Print the title, author, book_copies, and available_copies of the first book.
d.[0.5 pt] Print the total_books.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Sham Navathe

4th Edition

0321122267, 978-0321122261

More Books

Students also viewed these Databases questions

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago