ITEC 120 Back to Assignment index page
   
Assignment 4 - Textbook
Submit your program to your directory on neelix.

Description:  You will write a Texbook class and a driver to test this class.

The Textbook class:
Write a class to represent a Textbook. (It's OK to start with the one you were given for lab quiz 4 and add to it.)

Textbook

- # bookcount : int
- # value : double

- title : String
- author : String
- edition : int
- price : double
- used : boolean

+ Textbook ( title:String, author:String, edition:int, price:double, used:boolean)
+ discount ( percent:double ) : void
+ discount () : void
+ # getCount () : int
+ # getValue () : double
+ equals ( book:Textbook ) : boolean
+ toString () : String

The data:

You will have 2 static variables: bookcount and value. bookcount keeps track of how many textbooks have been instantiated. value keeps track of the total value of all textbooks which have been instantiated.

The methods:

The program4.java driver:
You will write a driver program which will test the different methods of the Textbook class. To do this, you'll read in and instantiate 3 textbooks, discount them, and print out info along the way so you can see what is happening. (It's OK to start with the one you were given for lab quiz 4 and add to it. Be sure to rename it program4.java)

The driver program which will read in the title, author, edition, price, and whether or not the textbook is used for three separate textbooks. You can read these from a file using redirection (see below). Here's a sample input file: books.txt.

All printing and reading will happen in the driver. There should be no System.out.prints or Keyboard stuff in the class file (Textbook.java).

Your driver program should:

Here's a sample run for the input data in books.txt:

Program outputs: There are 0 textbooks worth $0.00
Please enter title for book1:
User inputs: Calculus for Everyone
Program outputs: Please enter the author of Calculus for Everyone:
User inputs: D. Rivative
Program outputs: Enter the edition of Calculus for Everyone:
User inputs: 4
Program outputs: What is the price of Calculus for Everyone?
User inputs: 65.50
Program outputs: Is Calculus for Everyone a used textbook? (y or n)
User inputs: n
Program outputs: There are 1 textbooks worth $65.50
Please enter title for book2:
User inputs: Health and Physical Fitness
Program outputs: Please enter the author of Health and Physical Fitness
User inputs: Ben Dover
Program outputs: Enter the edition of Health and Physical Fitness:
User inputs: 3
Program outputs: What is the price of Health and Physical Fitness?
User inputs: $43.80
Program outputs: Is Health and Physical Fitness a used textbook? (y or n)
User inputs: y
Program outputs: There are 2 textbooks worth $109.30
Please enter title for book3:
User inputs: Kineseology
Program outputs: Please enter the author of Kinesiology
User inputs: Anna Tomey
Program outputs: Enter the edition of Kinesiology:
User inputs: 5
Program outputs: What is the price of Kinesiology?
User inputs: 54.25
Program outputs: Is Kineseology a used textbook? (y or n)
User inputs: n
Program outputs: There are 3 textbooks worth $163.55

Calculus for Everyone by D. Rivative, edition 4 NEW $65.50
Health and Physical Fitness by Ben Dover, edition 3 USED $43.80
Kineseology by Anna Tomey, edition 5 NEW $54.25

discounting Calculus for Everyone by D. Rivative, edition 4 NEW $65.50 by 5%
Calculus for Everyone by D. Rivative, edition 4 NEW $62.22

discounting Health and Physical Fitness by Ben Dover, edition 3 USED $43.80
Health and Physical Fitness by Ben Dover, edition 3 USED $38.54

discounting Kinesiology by Anna Tomey, edition 5 NEW $54.25
Kineseology by Anna Tomey, edition 5 NEW $50.45

There are 3 textbooks worth $151.22

Calculus for Everyone by D. Rivative, edition 4 NEW $62.22 and Health and Physical Fitness by Ben Dover, edition 3 USED $38.54 are different textbooks.

Kinesiology by Anna Tomey, edition 5 NEW $50.45 and Health and Physical Fitness by Ben Dover, edition 3 USED $38.54 are different textbooks.

TURNING IN YOUR PROGRAM: You will turn in two files. You'll have the driver program, named program4.java, and the textbook class, named Textbook.java. Submit both files to neelix in the appropriate folder. I will run your program with different input files. Do not change the format of the input file.


Redirection -

Ever get tired of typing input into your programs? You can redirect input from a file instead. You need your input typed into a text file, which needs to be in the same directory as the program you want to run. At the command line, type java programname < inputfile, for example:

java program4 < books.txt

and program4 will run, getting its input from books.txt instead of the keyboard. The above output was created by the input in books.txt.