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 String value is considered valid if it was not null or an empty String and a numeric value is considered valid if it was a non-negative value
Provide a method to display the book's information on the screen.
Create another class called BookStore. Here are the relevant attributes:
business name
array list of Book
Provide two constructors; the no-args constructor sets the business name to “Book Store”. The second constructor takes a parameter to initialize the business name. Both constructors create the ArrayList object
Provide an accessor (get) for each instance variable and mutator (set) for the String type instance variable.
Provide a method that adds a new book to the collection if the passed object was not null. Here is the method signature:
public void addBook(Book book)
Provide a method that takes an int parameter and displays on the screen the details of the book stored at that index position. This method must ensure that the parameter is a valid index position and display an error message if it is not.
Provide a method that takes a String parameter (the book title), searches the collection and displays the details of the Book object if the book was found in the collection. If the book was not in the collection the method will display a message stating that the book was not found. To compare strings use the equalsIgnoreCase() method of the String class.
Provide a method that uses for-each loop to display the details of all the books in the collection.
Create a mian method.In the method create three Book objects and add them to the ArrayList using method addBook().
Call the method that takes an int parmeter to display the book details and pass it 4 , then call it and pass the value 2.
Call the method that takes a String parameter and pass it a title of a book that does not exist in the collection then call the same method with a title of one of the books created earlier in the main method. Finally call a method to display all the details of all the books in the collection
Answer:
Here is the code and the screenshot, please refer the comments section for better understanding of the code. Also, do leave a comment if you have any questions/ doubts/ clarifications. I'll be glad to help you out. There are 2 classes which I am providing you, they are straight forward and simple. There is a main method in BookStore.java you can use for more testing. Thank you, Good Luck !!!

Book.java
public class Book { // attributes private String title; private String author; private int yearPublished ; private int bookPriceInCAD; // Constructors public Book(String title, String author, int yearPublished, int bookPriceInCAD) { this.title = title; this.author = author; this.yearPublished = yearPublished; this.bookPriceInCAD = bookPriceInCAD; } public Book() { } // Getters and Setters public String getTitle() { return title; } public void setTitle(String title) throws java.lang.Exception { if (title == null || title.length() == 0 || title.isEmpty()){ throw new IllegalArgumentException("Error in title"); // throw exception }else { this.title = title; } } public String getAuthor() { return author; } public void setAuthor(String author) { if (author == null || author.length() == 0 || author.isEmpty()){ throw new IllegalArgumentException("Error in author name"); // throw exception }else { this.author = author; } } public int getYearPublished() { return yearPublished; } public void setYearPublished(int yearPublished) { if (yearPublished <=0){ throw new IllegalArgumentException("Error in setting the published year"); // throw exception }else { this.yearPublished = yearPublished; } } public int getBookPriceInCAD() { return bookPriceInCAD; } public void setBookPriceInCAD(int bookPriceInCAD) { if (bookPriceInCAD <=0){ throw new IllegalArgumentException("Error in setting the book price in CAD"); // throw exception }else { this.bookPriceInCAD = bookPriceInCAD; } } @Override public String toString() { //helps in displaying return "Book{" + "title='" + title + '\'' + ", author='" + author + '\'' + ", yearPublished=" + yearPublished + ", bookPriceInCAD=" + bookPriceInCAD + '}'; } }
---------------------------------------------------------------------------------------------------------------------------------------
BookStore.java
import java.util.ArrayList; public class BookStore { private String businessName; private ArrayList<Book> bookArrayList; public BookStore(String businessName) { this.businessName = businessName; this.bookArrayList = new ArrayList<>(); } public BookStore() { this.businessName = "Book Store"; this.bookArrayList = new ArrayList<>(); } public BookStore(String businessName, ArrayList<Book> bookArrayList) { this.businessName = businessName; this.bookArrayList = bookArrayList; } public String getBusinessName() { return businessName; } public void setBusinessName(String businessName) { this.businessName = businessName; } public ArrayList<Book> getBookArrayList() { return bookArrayList; } public void setBookArrayList(ArrayList<Book> bookArrayList) { this.bookArrayList = bookArrayList; } public void addBook(Book book){ if (book != null){ bookArrayList.add(book); } } public void displayBookInfo(int i){ try{ Book b = this.bookArrayList.get(i); System.out.println(b); }catch (java.lang.Exception e){ System.out.println("Enter a valid integer, entered int is out of range ..."); } } public void searchBookByName(String bookName){ boolean flag = false; for (Book b : bookArrayList){ if (b.getTitle().equalsIgnoreCase(bookName)){ System.out.println(b); flag = true; break; } } if (flag == false){ System.out.println("Book not found ..."); } } public void displayBooks(){ for (Book b : bookArrayList){ System.out.println(b); } } public static void main(String [] args){ BookStore bookStore = new BookStore(); Book book1 = new Book("Operating System", "Galvin Silbechatz", 2000, 40 ); Book book2 = new Book("Complete Reference Java 11", "Hubert", 2018, 45 ); Book book3 = new Book("Let us C", "Yeshwanth Kanitkar", 1999,10); // adding books to bookstore bookStore.addBook(book1); bookStore.addBook(book2); bookStore.addBook(book3); // displaying out of range bookStore.displayBookInfo(4); // Valid range, displaying the book bookStore.displayBookInfo(2); // Search a book with invalid title bookStore.searchBookByName("Expert Guide"); // Search a book with valid title bookStore.searchBookByName("Complete Reference Java 11"); // Display all the books bookStore.displayBooks(); } }
----------------------------------------------------------------------------------------------------
Screenshot - Book.java



BookShop.java




Write a class called Book. Here are the relevant attributes: title author yearPublished bookPriceInCAD Provide...
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...
Code should be in C# Create a class called SavingsAccount. Use a static variable called annualInterestRate to store the annual interest rate for all account holders. Each object of the class contains a private instance variable savingsBalance, indicating the amount the saver currently has on deposit. Provide method CalculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12 – this interest should be added to savingsBalance. Provide static method setAnnualInterestRate to set the annualInterestRate to a new value....
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...
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 ( String) isbn...
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,...
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.
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....
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...
Application should be in C# programming language
Create a class called SavingsAccount. Use a static
variable called annualInterestRate to store the annual interest
rate for all account holders. Each object of the class
contains a private instance variable savingsBalance, indicating the
amount the saver currently has on deposit. Provide method
CalculateMonthlyInterest to calculate the monthly interest by
multiplying the savingsBalance by annualInterestRate divided by 12
– this interest should be added to
savingsBalance. Provide static method
setAnnualInterestRate to set the...
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...