Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

Class and Object Problem

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

Have you no shame? Have you no decency? Have you no tiny ad?
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
    Bookmark Topic Watch Topic
  • New Topic