Before you start, fill out a "Project Plan" in PSP with estimates of how long the program will be, how many defects you'll encounter, and how long it'll take you. (You will not be graded on how accurate your estimates are, but you are expected to make some kind of reasonable estimate.)
As you work on the programming part of the assignment,
keep track of all the error messages and other
defects you encounter using the
PSP forms
(click on "Input" under "Defect Removal Data").
(If you want to practice keeping time logs with
the PSP forms, you're welcome to, but they're not required for this assignment.)
should have instance variables for "price" and "kind", and a constructor to initialize them. For example, one could create a $300 guitar by saying
Instrument myInstrument = new Instrument(300.00,"guitar");
It should also have a method named salesTax that computes and returns the sales tax on the instrument. In the state where this music store is, sales tax is 6%, but there's no sales tax for instruments that cost less than $100.00. (New York State does something similar for clothes, but alas not for musical instruments!) So the sales tax on a $300 guitar would be $18.00, but the sales tax on a $25.00 harmonica would be $0.00.
You may want to make the instance variables private and provide access methods to allow the rest of the world to see (but not change) them. This is optional.
And, like all classes you write this semester, it should have a static void test method that creates a bunch of test cases, tries the methods on them, and prints the results.
represents all the instruments in the store. It has one instance variable: an array of Instruments (give it whatever name you like).
For now, the Inventory class constructor will set the array to contain eight instruments: let's say, a $300 guitar, a $25 harmonica, a $625 trumpet, an $850 keyboard, a $120 guitar, two $75 recorders, and a $2000 tuba. In the next homework assignment, this will change!
The Inventory class should have a method named totalPrice which computes and returns the total price of all the instruments in the array. Obviously, the right answer for now should be $4070, but your method must actually compute this from the contents of the array, so that when the size and contents of the array change in HW3, this method will still produce correct answers without needing to be changed at all.
The Inventory class should also have a method named averagePrice which computes and returns the average price of all the instruments in the array. Hint: Use the totalPrice method you've already written!
And, like all classes you write this semester, it should have a static void test method. It should create a single Inventory object, call each of the two methods, and print the results.
For each of the methods, and each of the classes, be sure to follow the design recipe! If you come to me for help writing the body of a method, and you don't already have a purpose, contract, examples, and header, I'll tell you to go away.
How to turn this in: Once you've got all of this working, run both of your "test" methods and save the output in a file named "output.txt" in the same folder as your program. Then "WinZip" the entire folder into a single file and send me an e-mail, attaching this ZIP file. If you have any comments about problems you encountered in writing the program, or things you learned, put these in the body of the e-mail.