Turn on thread page Beta
    • Thread Starter

    I'm in my first year of learning Java. Right now, we're only working with static methods to interpret data submitted in console. I'm trying to organize what I've got so far.

    In my spare time, I've coded methods to handle exceptions with recursion when reading Byte, Short, Int, Long, Float and Double values, as well as other methods to pose further conditions on those values (having a minimum/maximum value, the input has to be withing an array of values...).

    I'm trying to organize everything by function rather than data type, and I've recently found out about nested classes. Right now, my outer "Lire" (French for "Read", pastebin at the end) class has 11 nested classes (that handle numbers, numbers with minimal value, with maximum value...), each of those nested classes have 6 methods (sharing the same name as the methods in the other nested classes).

    The way it's organized in a package, the command I'd use to call the method would be (translated) console.Read.NumberMinimum.readS hort(100) to read a number of data type Short with the minimal value of 100.
    But, there's also console.Read.NumberMaximum.readS hort(100), console.Read.Number.readShort(), and subsequent variations for each data type (see the attached image).

    Is there a better way to organize my code?
    Having upwards of 77 methods in a single "Read" class, with 66 methods being exact duplicates of others with modified data types made it less readable.
    Are nested classes a good practice?
    I've tried searching online, but all I'm getting are blog post on how static methods are "evil". I have not taken a course on objects yet.

    Here's part of my code (error messages and variable names are in French):

    I've attached an image of the structure NetBeans displays with my code.
    Attached Images

    Recursively calling the method when an error occurs isn't a good idea because you'd easily run into a stackoverflow exception if the input is invalid once.
    • Thread Starter

    Using infinite loops rather than recursion: http://pastebin.com/FmjraDMx

    Still, how should I organize those methods? Are nested classes a good practice?
The home of Results and Clearing


people online now


students helped last year
A-level students - how do you feel about your results?
Useful resources

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.