• 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
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Java 1b: division by zero (ArithmeticException)

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess I don't have to catch every eventuality in my submitted code for the Java-1b assignment (??) Or am I subject to a disbelief?

The problem is, with the maths I have used in my Java-1b assigment, a user can cause this exception if the inputed "name" is too long (I'm not saying how long too long is ):



Any comments to this would be helpful, thanks.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Stuart,

Here is a hint: I did not use division to calculate the line break, therefore 'divide by zero' exceptions cannot occur.

Cheers,
Kelly
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you did everything while thinking of every possibility, your program could easily grow ten fold. Your program should be able to handle a name of any reasonable length. For example, "Ed", "Stuart", "Marilyn", "VanRenseeler".
 
Stuart Goss
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Kelly,

I had a solution without division or modulo, just counting as I went along. But I thought, "Well, that isn't much math is it?". So I bent myself to the task of calculating some things.

Anyway, if I can make the client only enter reasonable names then I don't have a problem with him/her, just with the QA department .

Thanks, Stuart
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic