Consider a class that keeps track of the sales of an item. An object of this class will have the attributes

• Number sold
• Total sales
• Total discounts
• Cost per item
• Bulk quantity
• Bulk discount percentage
and the following methods:
• registerSale(n) records the sale of n items. If n is larger than the bulk
quantity, the cost per item will be reduced by the bulk discount.
• displaySales displays the number sold, the total sales, and total discount.

a. Implement the class in Java.
b. Write some Java statements that test the class.


See the code in ItemSales.java.

Computer Science & Information Technology

You might also like to view...

Revise the class Pet, as shown in Listing 6.1 of Chapter 6, so that it is serializable. Write a program that allows you to write and read objects of type Pet to a file. The program should ask the user whether to write to a file or read from a file. In either case, the program next asks for the file name. A user who has asked to write to a file can enter as many records as desired. A user who has asked to read from a file is shown all of the records in the file. Be sure that the records do not scroll by so quickly that the user cannot read them. Hint: Think of a way to pause the program after a certain number of lines are displayed.

This project can be written by making modifications to ClassObjectIODemo, Listing 10.9, however the PetRecord class does not have the useful readInput() and toString() methods as Species, so they have been added. Also, note that PetRecord must implement Serializable.

Computer Science & Information Technology

Background images may be too distracting on and already full webpage.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

It is illegal to hack into any system without a permission of the system's owner

Indicate whether the statement is true or false.

Computer Science & Information Technology

What kind of data field or method can be used within its own class or in any classes extended from that class, but cannot be used by "outside" classes?

A. protected B. public C. private D. internal

Computer Science & Information Technology