Create a class called library with data attributes like acc_number, publisher, titleand author. The methods of the class should includei). read() – acc_number, title, author.ii). compute() - to accept the number of days late, calculate and display the finecharged at the rate of $1.50 per day.iii). display the data
Question
Create a class called library with data attributes like acc_number, publisher, titleand author. The methods of the class should includei). read() – acc_number, title, author.ii). compute() - to accept the number of days late, calculate and display the finecharged at the rate of $1.50 per day.iii). display the data
Solution
To create a class called "library" with data attributes like "acc_number", "publisher", "title", and "author", follow these steps:
- Define the class "library" using the class keyword.
- Inside the class, define the data attributes "acc_number", "publisher", "title", and "author".
- Create a method called "read()" inside the class. This method should accept and store the values of "acc_number", "title", and "author".
- Create another method called "compute()" inside the class. This method should accept the number of days late as a parameter. Inside the method, calculate the fine by multiplying the number of days late by $1.50. Display the calculated fine.
- Finally, create a method called "display()" inside the class. This method should display the values of all the data attributes.
Here is an example implementation in Python:
class Library:
def __init__(self):
self.acc_number = ""
self.publisher = ""
self.title = ""
self.author = ""
def read(self):
self.acc_number = input("Enter account number: ")
self.title = input("Enter title: ")
self.author = input("Enter author: ")
def compute(self, days_late):
fine = days_late * 1.50
print("Fine charged: $", fine)
def display(self):
print("Account number:", self.acc_number)
print("Title:", self.title)
print("Author:", self.author)
# Example usage:
my_library = Library()
my_library.read()
my_library.compute(5)
my_library.display()
This implementation creates a class called "Library" with the desired data attributes and methods. The "read()" method prompts the user to enter the account number, title, and author. The "compute()" method calculates and displays the fine based on the number of days late. The "display()" method prints the values of the data attributes.
Similar Questions
In a Library Management System, create a class ‘LibUser’ and get the name, age, address, book name, book type, date of issue, date of return (current date) and penalty amount. For ‘age’ create user defined exception class and check if age is a negative number and print “Please enter correct age”.Calculate the number of days of book in use as (current date - date of issue). If number of days of book in use is greater than 15 days and then handle the exception and print “Fine to be paid”. Penalty amount = (number of days of book in use – 15) * 10.If the name entered contains numbers or any special characters (other than alphabets and spaces), then handle it using exception handling and print “Enter your Correct Name”.InputName (String)Age (Integer)address (String)book name (String)book type (String)date of issue (format: yyyy-mm-dd) (String)Current date (format: yyyy-mm-dd) (String)Penalty amount (Integer)OutputUser defined string according to exception
Design a library catalog system with a base class Item and derived classes Book, DVD, and Magazine. Each item has an item ID and the number of days overdue. Implement a virtual function, calculateLateFees, to calculate the total overdue amount. Calculate the total overdue amount for all items and display it.Overdue Amount Calculation:For Books: Rs. 0.25 per day overdueFor DVDs: Rs. 0.50 per day overdueFor Magazines: Rs. 0.10 per day overdue
Accept the number of days from the user and calculate the charge for library according to following:Till five days: Rs 2/daySix to ten days: Rs 3/day11 to 15 days: Rs 4/dayAfter 15 days: Rs 5/day
Ask user for employee name and pay rate.Create the employee object.Ask user for the number of days the employee worked.For each day it will ask the user for number of hours that employee worked and use the add_hours function to add this to the list of hours_worked in employee class.It will display the employee data as follows (use f string to format the output):Employee Name: Joe DoePay Rate: $ 25.75 per hourTotal number of hours worked: 39.45Total Salary: $ 1015.84
In an online electric bill system to pay bill, create a class ‘Consumer’ and get the name, consumer number, address, last date for payment, current date and penalty-per-day information. For ‘consumer number’ create user defined exception class and check if it is a negative number and print “Enter correct data”.Calculate the total penalty as (days* penalty-per-day). If the total number of days exceeded 5 handle the exception and print “Not permitted”. (days=current date-last date for payment)If the name entered contains numbers or any special characters (other than alphabets and spaces), then handle it using exception handling and print “Enter correct name”. InputGet the following detailsName (String)Consumer Number (Integer)Address (String)yyyy-mm-dd (last date) (String)yyyy-mm-dd (current date) (String) Penalty in Rs. per day (Integer)outputuser defined string according to the exception occured
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.