You are on page 1of 1

Computer Science Fundamentals II Tuesday, September 24, 2019

Quiz 1
CS1027A University of Western Ontario

Introduction

The Ontario Scientific London Library requires a new program to store their information on
books, authors, and publishers. The library has asked you to create an object to hold book
information called Book.java.

Book.java

The Book class encapsulates a student using the private variables:


• bookName: the name of the book (of type String),
• bookAuthor: the author of the book (of type String), and
• bookISBN: the ISBN number of the book (of type int).
and the methods:
• A constructor method, Book(), with 3 parameters: the book name, book author, and
book ISBN. This method creates an instance (object) of the class Book.
• Getter methods: getBookName(), getBookAuthor(), and getBookISBN() that return
the book name, book author, and book ISBN, respectively.
• Setter methods: setBookName(), setBookAuthor(), and setBookISBN() that saves the
book name, book author, and book ISBN, respectively.
• Method toString(): returns a string containing the values of the object’s private vari-
ables.
When a parameter and a variable have the same name, for example within Book.java’s
constructor both the private variable private String bookName and the parameter String
bookName are visible, then this.bookName refers to the private variable and bookName refers
to the parameter.

Hint: start your answer like this:

public class Book {

You might also like