I am having trouble completing (or even starting for that matter) exercise 6-3 in Murach's Java SE 6. I have looked over the chapter several and have even tried to come up with ways that the example code could help me. I thought I had a nice start and was almost done, but once I got to step 3 I realized that I was trying to do too much. So I went back to redo some of the class, but I just ended up confusing myself even more.
Here are the instructions followed by the provided code:
Exercise 6-3 Use objects in the Invoice Application
In this exercise, you'll create an Invoice class and construct objects from it as you conver the Invoice application to an object-oriented application.
1. Open the InvoiceApp and Validator classes in the ch06\Invoice directory. This is yet another version of the Invoice application. Then, compile and run the classes to see how this application works.
2. Start a new class named Invoice and save in the same directory. Then, write the code for this class so it provides all of the data and all of the processing for an Invoice object. Its constructor should require the subtotal and customer type as its only parameters, and it should initialize instance variables for discount percent, discount amount, and invoice total. Its methods should include the required get and set methods, plus a method named getInvoice that returns a string that contains all of the data for an invoice in a printable format. When you're done, compile the Invoice class.
3. Modify the code in the InvoiceApp classes so it creates an Invoice object and uses its getInvoice method to get the formatted data fro invoice. That should simplify this class considerably. Then compile and test this class to make sure that this application works the way it did in step 1.
The InvoiceApp Class
The Validator Class
What I had done with the Invoice class when I realized that I messed up:
I realize that I am a complete noob with Java. Any help that anyone could provide will be greatly appreciated.
You should look at the methods inside of the invoice class and examine what they do. You should then take a look at the Invoice app class and see where the methods in the invoice class could be used to save you steps, or reduce the number of instructions in the class.
Hint: try to find things in the invoice app class that can be accomplished by the invoice class methods
"If the facts don't fit the theory, get new facts" --Albert Einstein
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop