• 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 ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Bear Bibeault
  • paul wheaton
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Mikalai Zaikin
  • Piet Souris
Bartenders:

Switch Statement and GUI

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everybody!! I was hoping to get a few pointers on the following code. I have class Sales and class Salesman. Class Salesman has attributes name and sales. I am mainly stuck because I am not sure how I should set up the switch statement in class Salesman.

I want to calculate the total sales for each salesman and the grand total of those sales. I realize the GUI is not the best, but I guess it is ok. LOL. So the user will input their name, the product they sold, and how many of that product was sold. I also put a button for the user to click when they are done entering their information and a button to indicate that all salesmen have entered their information and may be totaled.

Then it should display the total retail value of all products sold for each salesman and then the total of all sales. The final information will be printed to the text area where the salesmen names are in alphabetical order (which I haven't even began to figure out yet) and then their sales to the right of their name (one or two tabs over). Under that I will have the grand total: Total$0.00





Thanks so much for any tips or suggestions!! Much appreciated!!
[ February 18, 2006: Message edited by: Holly Leery ]
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's an adage in "Refactoring" by Martin Fowler that goes something like "If your design can't handle a new requirement, refactor." I'd find the exact quote, but the book is at work. The point is rather than trying to hack code together to meet some new requirement that your design isn't able to handle you should refactor the code in order to.

I only briefly looked at the code but one thing strikes me immediately and that is there seems to be a need for at least one new class: Product. Rather than trying to have your GUI dictate the price of a product. Instead, how about moving this information to it's own Product class. You could then have method such as getPrice() that returns a monetary value. It would also then be very easy to pass an array of Products to your GUI so that when a new Product gets added later you don't have to change the GUI. If you override toString() in Product to return it's name you can easily add each Product to the JComboBox and it will display it properly. Then all you have to do is use getSelectedItem(), cast it to a Product, then use getPrice(). That's a start anyway.
 
It's fun to be me, and still legal in 9 states! Wanna see my tiny ad?
Low Tech Laboratory
https://www.kickstarter.com/projects/paulwheaton/low-tech-0
reply
    Bookmark Topic Watch Topic
  • New Topic