• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using JOptionPane in NoSalesException  RSS feed

 
Holly Leery
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • 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:
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!