created 11/25/08

# Chapter 32 Programming Exercises

## Exercise 1 — Copy Shop

Design and implement a `CopyJob` class and a `CopyJobTester` class that tests your class. `CopyJob` objects represent one work order in a copy shop. A work order consists of:

• The number of copies.
• The number of pages per copy.
• If the pages are printed one-sided or two-sided.
• If the job is stapled.

For example, a possible job could consist of 25 copies, 10 pages per copy, printed two sided, each copy stapled.

For example, another job could consist of 100 copies, 30 pages per copy, printed one sided, no staples.

If a job is stapled, it must consist 20 or fewer sheets of paper (20 pages for one-sided printing, 40 pages for two-sided printing).

Your class should have four instance variables of type `int` or `boolean` as appropriate. Create a constructor that takes four parameters and initializes each of the instance variables of its object. Don't do any error checking in the constructor

Now write four methods:

`void showJob()` prints a nicely formatted display of a job.
`void setCopies(int num)` changes the number of copies in the object to `num`.
`void setPages(int num)` changes the number of pages in the object to `num`.
`int jobCost()` returns the cost of the job.

A job costs \$0.04 per sheet of paper, plus \$0.03 per page, plus \$0.02 per copy if stapled or \$0.25 per copy if spiral bound. For example, the first possible job would cost:

• 25 copies
• 10 pages per copy
• double sided
• staples

10 pages per copy = 10 * \$0.03 = \$0.30 per copy
10 pages per copy double sided = 5 sheets per copy = \$0.04 * 5 = \$0.20
staples = \$0.02 per copy total per copy = \$0.30 + \$0.20 + \$0.02 = \$0.52 per copy. total cost = 25 copies * \$0.52 = \$13.00

Notice that if there are an odd number of pages in a double-sided job, the last sheet of paper will have only one page printed on it. For example, a five page double sided job will take three sheets. If the data in the instance variables is incorrect write an error message and return a cost of zero dollars. Examples of incorrect data are negative amounts for copies or pages, and more than 20 sheets for stapling.