Name : Comp 240 Quiz Programming 1
ID # : Mar 03, 2005
2/2
State clearly all of your assumptions.
Good luck.
Q1. (60 pt)
Create a class called “InvoiceLine” that a hardware store might use to represent a line of an invoice for an item sold at the store.
1.a. (10 pt)
An invoice line should include four pieces of of information as instance variables:
· a part number (type String)
· a part description (type String)
· a quantity of the item being purchased (type int)
· a price per item (type double)
1.b. (10 pt)
Your class should have a constructor that initializes the four instance variables. Note, if the quantity or the price per item is not positive, they should be set to zero. You may also use the corresponding set method here.
1.c. (10 pt)
Provide a set and a get method for each instance variable. Note, if the quantity or the price per item is not positive, they should be set to zero.
1.d. (10 pt)
Provide a method named getAmount that calculates the line amount (i.e., multiplies the quantity by the price per item), then returns the amount as a double value.
1.e. (10 pt)
Provide a method named displayInvoiceLine that displays the information of the invoice line. Use tab characters to form a tabular format.
1.f. (10 pt)
Do not forget to write explanatory comments within your code.
Make use of appropriate indentations, and white spaces to increase readability.
You should submit both the .java file and the compiled .class file.
Q2. (40 pt)
Write a test application “InvoiceTest.java” to utilize and test the InvoiceLine class that you have created in Q1.
2.a. (10 pt)
As a test case, assume a customer who purchases two items at the store:
· a hard disk with part number “HDD”, part description “Hard Disk” and unit price 79.9 YTL
· four memory units with part number “RAM”, part description “Memory” and unit price 35.55 YTL
Create two instances of invoice lines with these information, line1 and line2.
2.b. (5 pt)
Output the invoice to the console.
2.c. (10 pt)
Assume that the customer has a special discount card which provides a 10% discount on all items. Using the set methods that you have created in Q1.c, update the unit prices of the items in the previous invoice.
2.d. (5 pt)
Output the discounted invoice to the console. You may repeat your code that you have used in Q2.b.
2.e. (10 pt)
Do not forget to write explanatory comments within your code.
Make use of appropriate indentations, and white spaces to increase readability.
You should submit both the .java file and the compiled .class file.
The output of the application should be similar to this:
Part Description Qty Price Amount
------
HDD Hard Disk 1 79.90 79.90
RAM Memory 4 35.55 142.20
------
Total 222.10
Part Description Qty Price Amount
------
HDD Hard Disk 1 71.91 71.91
RAM Memory 4 31.99 127.98
------
Total 199.89
Note here that 35.55 YTL with a 10% discount is NOT exactly 31.99 YTL. Moreover, 31.99 YTL x 4 pieces does NOT give an amount of 127.98 YTL.
Why?