Write a definition for a class named Book with attributes title, price and author, where author is a Contact object and title is a String, and price is a float number.
You also need to define the Contact class, which has attributes name and email, where name and email are both String.
Instantiate a couple of Book objects that represents books with title, price and author (You can come up with the attributes values for each object)
Write a function named print_book that takes an object of Book and prints out the value of its attributes. (Make the message friendly to read, for example "Book title: [sometitle]", "Book price: [$33.75]", etc
Write a function named which_is_more_expensive that takes two Book objects as parameters and returns the reference of the Book object with higher price
Write a function named which_is_more_expensive_by_copy that takes two Book objects as parameters and returns a copy of the Book object with higher price
Write a function named calculate_total_price that takes two Book objects as parameters and returns the total price of the two books
Make functions calls of all these functions by passing the Book objects you created.
[Check point] Submit your python code as .py file in text format, and capture the screens of your program running showing the input and output.
class Book:
def __init__(self,title,price,a1):
self.title=title
self.price=price
self.name=a1.name
self.email=a1.email
class Author:
def __init__(self,name,email):
self.name=name
self.email=email
array_book=[]
a1=Author("Robert","[email protected]")
b1=Book("book1",10.0,a1)
#appending objects to an array
array_book.append(b1)
a2=Author("Rahim","[email protected]")
b2=Book("book2",20.0,a2)
array_book.append(b2)
a3=Author("Ramu","[email protected]")
b3=Book("book3",30.0,a3)
array_book.append(b3)
#searching an existing book
def print_book(search):
count=0
for i in array_book:
if(i==search):
count=1
print("Title is::"+i.title,"\nPrice is::",i.price,"\nAuthor Name
is::",i.name,"\nAuthor Name email is::",i.email)
if(count==0):
print("Book Not Available")
#finding more expensive book
def which_is_more_expensive(item1,item2):
count=0
for i in array_book:
if(i==item1):
count+=1
item1=i
price1=i.price
if(i==item2):
count+=1
item2=i
price2=i.price
if(count==2):
if(price1>price2):
return item1
else:
return item2
else:
print("Book mentioned is/are not Available")
#calculating the cost of two existing books
def calculate_total_price(item1,item2):
count=0
price=0
for i in array_book:
if(i==item1):
count+=1
price+=i.price
if(i==item2):
count+=1
price+=i.price
if(count==2):
return price
else:
print("Book mentioned is/are not Available")
print_book(b1)
check=which_is_more_expensive(b2,b3)
#checking the returned object
print("\n",check.name,"'s book is more expensive\n")
value=calculate_total_price(b1,b2)
#checking the returned value
print("Cost of two books is",value)
#sample input and output
Write a definition for a class named Book with attributes title, price and author, where author...
Write a class named Book containing: Two instance variables named title and author of type String. A constructor that accepts two String parameters. The value of the first is used to initialize the value of title and the value of the second is used to initialize author. A method named toString that accepts no parameters. toString returns a String consisting of the value of title, followed by a newline character, followed by the value of author.
Create a Python file (book.py) that has a class named Book. Book class has four attributes, title (string), author(string), isbn(string), and year(int). Title - the name of the book. Author - the name of the persons who wrote the book. ISBN - is a unique 13 digit commercial book identifier. Year - the year the title was printed. Your class should have the following methods: (1) __init__(self, title, author, isbn, year): This method called when an object (book) is created...
Create a Python file (book.py) that has a class named Book. Book class has four attributes, title (string), author(string), isbn(string), and year(int). Title - the name of the book. Author - the name of the persons who wrote the book. ISBN - is a unique 13 digit commercial book identifier. Year - the year the title was printed. Your class should have the following methods: (1) __init__(self, title, author, isbn, year): This method called when an object (book) is created...
cs55(java) please. Write a class called Book that contains instance data for the title, author, publisher, price, and copyright date. Define the Book constructor to accept and initialize this data. Include setter and getter methods for all instance data. Include a toString method that returns a nicely formatted, multi-line description of the book. Write another class called Bookshelf, which has name and array of Book objects. Bookself capacity is maximum of five books. Includes method for Bookself that adds, removes,...
Book: - title: String - price: double +Book() +Book(String, double) +getTitle(): String +setTitle(String): void +getPrice(): double +setPrice(double): void +toString(): String The class has two attributes, title and price, and get/set methods for the two attributes. The first constructor doesn’t have a parameter. It assigns “” to title and 0.0 to price; The second constructor uses passed-in parameters to initialize the two attributes. The toString() method returns values for the two attributes. Notation: - means private, and + means public. 1....
Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use implements Comparable<Book> in the class definition. Now, all book objects are instances of the java.lang.Comparable interface. Write a test program that creates an array of ten books. 1. Use Arrays.sort( Book[]l books) from the java.util package to sort the array. The order of objects in the array is determined using compareTo...) method. 2. Write a method that returns the most expensive book in the...
Language is Java! Write a class named Book that has two public String variables named title, and author. Do not add or change any other code.
C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (String) edition ( int) published year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method// that return sting representation of Book object. 2-Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title...
C# assistance please help Write the source code for a C# program (i.e., a separate class) named “BookDemo” that uses the Book class below and does the following in the Main method of BookDemo: 1) Declare local variables for book title and author, and initialize the variables to “C# Programming” and “Farrell” 2) Instantiate a Book object using the information from Step 1 3) Print the summary of the book object using the displaySummary() method in the Book class class...
A java class named Book contains: instance data for the title, author, publisher and copyright year a constructor to accept and initialize the instance data variables set and get methods a toString() method to return a formatted, multi-line description of the book Produce a child class that inherits from Book. The class is called Dictionary. Dictonary must include: instance data that describes the number of words in the dictionary a constructor that takes in all information needed to describe a...