• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Using JOptionPane in NoSalesException

 
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 everyone! I am having some trouble creating a NoSalesException. I am not getting any errors or anything like that, it just is not running properly. When I first run the program it pops up 5 times and then never pops up again. I think the exception should be thrown from calculateSales and handled from the calling method; however I could not get that to work. When I handle this exception, it will print a warning message dialog box that states the name of the salesman and that he has no sales. So here is my Sales code and NoSalesException.

NoSalesException:


Sales:
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just reading through the code, it seems you have the try/catch and while the
wrong way around

as written, if sales == 0.0, the exception will be thrown, breaking out of
the while(), which doesn't appear to be what you want

basically you have this


and you possibly want something like this
 
Holly Leery
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean something like this:



I still can't get it to run right. It just pops up on every name.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
each time sales = 0, in your catch{} you display a messagebox showing
salesm.getName() + " has no Sales!!"
for every salesman in myList, regardless of whether the salesman has 0 sales or not.
Note: the current data of the while() has not been added to myList yet,
so it seems the salesman with 0 sales triggers a printout of all the other
salesmen, declaring their sales are 0.

is this what you really want?

are you trying to exclude a salesman with 0 sales from myList?

if so, it might be easier to do without the NoSalesException



perhaps a bit more info on what the requirements are for a salesman with 0 sales
might get you a better/more detailed answer
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic