Program #1

Due Friday, 1/26 2:00 pm

Purpose

The objectives for this assignment are to:

Discussion

Programming in Java typically requires the ability to define classes, and then to create and use objects based on those classes. In this assignment, you will design a class, nearly from scratch, then create objects based on that design, and then use the objects in an Applet object.

Classes describe objects. Objects have two types of components: Responsibilities and State. The responsibilities describe actions or responses that every object based on that class can perform. In other words, all objects in a class have the same responsibilities. The State is the set of values that comprise an object (instance) of the class. In contrast to responsibilities, each object's state is usually different from that of the other objects of the same class.

For instance, consider a class which describes a bank account. There will be a lot of accounts, but the responsibilities of all accounts will be the same: to allow adding money, taking money away, and so on. However, the state (amount of money) of every account object is different.

Instance variables hold the state. An object of the class has a "has-a" relationship with its instance variables.

Methods carry out the responsibilities.

Methods should fall cleanly into one of the two above categories.

In this assignment you will create a class which describes books. There are certain things a book can do: display information about itself such as its title and its price, and so on.

You will define features of books in a Book class. You will then use that class to create 2 specific book objects. Finally, you will send messages to those books asking them to do things they are supposed to know how to do.

Assignment Details

Create an applet with these features:
  • It contains a (has-a) Book class.
  • You must write your book methods in a way that would work correctly even if there were different books used in the course.

    The accessor methods in the Book class should be named as follows:
    getPublisher
    getTitle 
    getAuthor 
    getYear
    getISBN

    This method returns the publisher information.
    This method returns the title information.
    This method returns information about the author.
    This method returns the year of publication of the book.
    This method returns the ISBN information.
     
    The mutator methods in the Book class should be named as follows:
     
    setPublisher
    setTitle
    setAuthor
    setYear
    setISBN
    This method sets the publisher information.
    This method sets the information about the title.
    This method sets the information about the author.
    This method sets the year of publication of the book.
    This method sets the ISBN information. 

    Your Book class must have the ten methods mentioned above. If you wish, you can also provide a constructor which does not require any input parameters, and can provide additional constructors which accept parameters but these are not required. If you do not provide any constructors, Java will provide a simple one with no parameters for you.
     

    Turn In

    Turn in the following electronically: