Hot answers tagged

3

Avoid string addition String addition is not good for building up strings from many pieces ... especially inside of loops. You should use StringBuilder instead. StringBuilder sb = new StringBuilder(); // ... omitted ... sb.append(arr[j]).append(',').append(arr[j]).append(' '); // ... omitted ... String s = sb.toString(); System.out.println(s); ...


3

Unfortunately I don't have time to finish my answer right now, but here's what I think so far: Main.java If your whole program is built around reading and manipulating a single file, it's customary and useful to take the name of that file in as a parameter (i.e. read it from args) instead of hardcoding it. (In future versions you might replace the filename ...


3

Interface For clarity, isMagicPresent() should accept a java.io.File (or java.nio.file.Path) to emphasize that the argument is a path and not the contents of a file. The default constructor should be suppressed. Implementation To read a big-endian int, use DataInputStream.readInt(). Then you can compare the magic number to 0xCAFEBABE rather than four ...


2

General RNG is a poor name for a class that generates passwords, not random numbers. PasswordGenerator would be better. In idiomatic Java, { are on the same line, not on a newline. else is on the same line as }. In idiomatic Java, method and variable names use camelCase. Avoid acronyms - they tend to make the code harder to read. Using final indicates ...


2

close You had an opportunity to acquire (and then close) this resource using try-with-resource private static final Scanner scanner = new Scanner(System.in); Similarly for this one: new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); streaming input You're reading 200,000 numbers here: String[] expenditureItems = scanner.nextLine()....


1

Short take … most efficient way to do this resources including developer time … of uncommented code: Starting with testCreateTree() raises hope for a stab at test first - I don't see it. What is this above: is there more to tree than Node, how does searchable manifest? there is no interface for Node (and testCreateTree() shows one is urgently needed) (...


1

General In idiomatic Java, open curly braces belong on the same line, not a newline. In idiomatic Java, variable names use camelCase. Underscores are only used when naming constants. Classes not designed for extension should be marked as final. Variables that will not be reassigned should be marked as final. This clarifies the design intent of the author ...


1

I think this bit is worth refactoring: public void printOptions(){ System.out.println("Options:"); System.out.println("0. Quit"); System.out.println("1. Add a new dog"); System.out.println("2. Add a new cat"); System.out.println("3. Print all animals"); System.out.println("4. Delete an animal"); ...


1

OOP considerations: Dog and Cat are both animals; You should have Dog and Cat classes which extend Animal. You have basically three concerns (business logic) in your application: (1) Get input from command line, (2) Validate inputs and translate inputs to entity, (3) Apply CRUD operations to perform on entities. You can create one interface for each ...


1

For me overall it was very easy to read and follow. Nitpicking: Since you want to accept a single input, you can actually check for if (args.length == 1) You are already chaining the conditionals so why not the following? private static boolean isMagicPresent(String file) throws IOException { try (InputStream is = new FileInputStream(file)) { ...


1

Guard Arguments put does not check for e == null. Are null values allowed? If not, add an argument guard if (e == null) throw new NullPointerException();. Naming Conventions Call your class BlockingStack to conform to Java naming guidelines concerning concurrent collections. max should be called capacity. A collection's capacity is its maximum size. As ...


1

Good job separating concerns Your tetris game-board model, piece and UI code is nicely separated in classes, so each one has its own responibility. Well done! Don't use magic values, use Enum public Piece(int f) This switches on a magic value of f. Piece is a excellent candidate for Enum! public enum Piece { L, J, T, Z, I, ... } Enum works as class ...


Only top voted, non community-wiki answers of a minimum length are eligible