Inlab 2: Book Class and Driver

Due: Friday 29 January at 6:00 pm

Purpose

Partners

This is an individual assignment, though collaboration (not solution sharing) is allowed.

Problem Statement

The Montana State University book store needs your help to build a system that keeps track of inventory. You will build a Book class to represent books and a Driver with which you will manipulate instances of the Book class. A book object consists of a title (such as "Ultra Running"), a number of books in stock (such as 132), and a cost per book (such as 12.95).

Assignment

Book Class

  1. After signing into one of the lab computers, open up the BlueJ environment and create a new project called Inlab2.
  2. Within the Inlab2 project, create a new class called Book.
  3. Create instance variables in the book class to fit the specifications detailed in the Problem Statement. (You can name the variables however you see fit)
  4. Make a constructor that takes a book's title, number in stock, and cost as parameters and sets the correct variables.
  5. Make a "get method" for each instance variable.
  6. Make a method that will calculate and return the total value of that book the store has in stock (ex: 22 copies of "Dracula" at $7.55 per book means the total value of $166.10).

Driver Class

  1. In the Inlab2 project, create a class called Driver with a main method like we did in class. Main method header: public static void main(String[] args)
  2. Within the main method, create a variable called book1 that can hold an instance of the Book class.
  3. Create an instance of the Book class where the book's name is "Dracula", cost is 7.55, and number in stock is 22 and store this instance in book1.
  4. Print out the name and value of book1 using the correct methods from the Book class.
  5. Create a second instance of Book with parameters of your choosing and store in a variable called book2. Print out the name and value of book2.
  6. Run the main method in Driver (right click Driver, select void main(String[] args), select "ok") and check that the output for book1 and book2 are both correct.

Submission

By Friday evening at 6:00 pm, submit the files Book.java and Driver.java into the appropriate D2L dropbox folder. DO NOT SUBMIT Book.class or Driver.class.

Grading - 10 points