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","name1@etc.com")
b1=Book("book1",10.0,a1)
#appending objects to an array
array_book.append(b1)
a2=Author("Rahim","name2@etc.com")
b2=Book("book2",20.0,a2)
array_book.append(b2)
a3=Author("Ramu","name3@etc.com")
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.
Write a class called Book. Here are the relevant attributes: title author yearPublished bookPriceInCAD Provide a constructor that takes parameters to initialize all the instance variables. The constructor calls the mutator (set) methods to initialize the instance variables. Provide an accessor (get) and mutator (set) for each instance variable. The mutators all validate their parameters appropriately and use them only if valid. If the passed parameter was invalid an IllegalArgumentException will be thrown with a proper error message A...
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...
Java Program: Design a class “Book” with the data attributes title - String, author - String, yearPublished - integer and price - double. Write a parameterized constructor that initializes the attributes. Write accessor and mutator methods, and a print method that prints all of the attributes. In the main method, create a single object and give it values of your choice. Call the print method to print the values. Sample Run: The Book is: The Art of Computer Programming Donald...
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...
JAVA This PoD, builds off the Book class that you created on Monday (you may copy your previously used code). For today’s problem, you will add a new method to the class called lastName() that will print the last name of the author (you can assume there are only two names in the author name – first and last). You can use the String spilt (“\s”) method that will split the String by the space and will return an array...
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.