Question

In: Computer Science

. Create a class called Book to represent a book. A Book should include four pieces...

. Create a class called Book to represent a book. A Book should include four pieces of information as instance variables‐a book name, an ISBN number, an author name and a publisher. Your class should have a constructor that initializes the four instance variables. Provide a mutator method and accessor method (query method) for each instance variable. Inaddition, provide a method named getBookInfo that returns the description of the book as a String (the description should include all the information about the book). You should use this keyword in member methods and constructor. Write a test application named BookTest to create an array of object for 30 elements for class Book to demonstrate the class Book's capabilities.

Solutions

Expert Solution

CODE IN JAVA:

Book.java file:


public class Book {
  
   private String bookName ;
   private String ISBNNumber ;
   private String authorName ;
   private String publisher ;
   public Book(String bookName, String iSBNNumber, String authorName, String publisher) {
      
       this.bookName = bookName;
       ISBNNumber = iSBNNumber;
       this.authorName = authorName;
       this.publisher = publisher;
   }
   public String getBookName() {
       return bookName;
   }
   public void setBookName(String bookName) {
       this.bookName = bookName;
   }
   public String getISBNNumber() {
       return ISBNNumber;
   }
   public void setISBNNumber(String iSBNNumber) {
       ISBNNumber = iSBNNumber;
   }
   public String getAuthorName() {
       return authorName;
   }
   public void setAuthorName(String authorName) {
       this.authorName = authorName;
   }
   public String getPublisher() {
       return publisher;
   }
   public void setPublisher(String publisher) {
       this.publisher = publisher;
   }
  
   public String getBookInfo() {
       return "Book [bookName=" + bookName + ", ISBNNumber=" + ISBNNumber + ", authorName=" + authorName
               + ", publisher=" + publisher + "]";
   }
  
  
}

TestBook.java file:

import java.util.Scanner ;
public class TestBook {

   public static void main(String[] args) {
      
       Scanner sc = new Scanner(System.in);
       System.out.print("Enter book name : ");
       String book = sc.nextLine();
       System.out.print("Enter ISBN number : ");
       String ISBN = sc.nextLine();
       System.out.print("Enter author name : ");
       String author = sc.nextLine();
       System.out.print("Enter publisher : ");
       String publisher = sc.nextLine();
       Book b = new Book(book, ISBN, author, publisher);
       System.out.println(b.getBookInfo());

   }

}

OUTPUT:


Related Solutions

JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
Invoice Class - Create a class called Invoice that a hardware store might use to represent...
Invoice Class - Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables—a part number (type String), a part description (type String), a quantity of the item being purchased (type int) and a price per item (double). Your class should have a constructor that initializes the four instance variables. If the quantity passed to the constructor is...
Invoice Class - Create a class called Invoice that a hardware store might use to represent...
Invoice Class - Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables—a part number (type String), a part description (type String), a quantity of the item being purchased (type int) and a price per item (double). Your class should have a constructor that initializes the four instance variables. If the quantity passed to the constructor is...
By using Python: a. Make a class called Book. The __init__() method for Book should store...
By using Python: a. Make a class called Book. The __init__() method for Book should store two attributes: a title and an author. Make a method called book_info() that prints these two pieces of information, and a method called book_available() that prints a message indicating that the book is available in the library. b. Create an instance called book1 from your class. Print the two attributes individually, and then call both methods. c. Create three different instances from the class,...
3.12 (Invoice Class) Create a class called Invoice that a hardware store might use to represent...
3.12 (Invoice Class) Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables-a part number (type String), a part description (type String), a quantity of the item being purchased (type int) and a price per item (double). Your class should have a constructor that initializes the four instance variables. Provide a set and a get method for...
with PHP Create a class called Invoice that a hardware store might use to represent an...
with PHP Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables — a part number (type String), a part description (type String), a quantity of the item being purchased (type int) and a price per item (double). Your class should have a constructor that initializes the four instance variables. Provide a set and a get method...
----------------------------------------------------------------------------------------------- Create a class called MathOperations that a teacher might use to represent the basic type...
----------------------------------------------------------------------------------------------- Create a class called MathOperations that a teacher might use to represent the basic type of mathematical operations that may be performed. The class should include the following: Three double private variables as instance variables, number1, number2, and result. Your class should have a default constructor that initializes the three instance variables to zero. Your class should also have a constructor that initializes the two instance variables (number1 and number2) to the value entered by the user from keyboard....
Using C# Create a class called Artist that contains 4 pieces of information as instance variables:...
Using C# Create a class called Artist that contains 4 pieces of information as instance variables: name (datatype string), specialization – i.e., music, pottery, literature, paintings (datatype string), number of art items (datatype int), country of birth (datatype string). Create a constructor that initializes the 4 instance variables. The Artist class must contain a property for each instance variable with get and set accessors. The property for number should verify that the Artist contributions is greater than zero. If a...
In Angel, you will find a class called Employee. This class should include a constructor which...
In Angel, you will find a class called Employee. This class should include a constructor which sets name to blanks and salary to $0.00 and a constructor which sets name to a starting name and salary to a set amount. Additionally, the class should include methods to set the name and salary and return the name and salary. Create another method to return the name and salary nicely formatted as a string (hint – research the toString method). You will...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT