Hot answers tagged

7

Nice project, find below my suggestions. Clearing the terminal There are more than 20 System.out.println(" ") in one line and then again a few lines below. Create a method to clear the terminal and shorten the code with a for-loop. There are also other ways to clear the terminal. Duplicated code Requesting the input from the user is duplicated ...


5

public LocalDateTime parseDate(String dateString) { Your formatting choices are partly odd, if in doubt, stick to the IDE default formatting (or the formatting of the project. checkArgument(!Strings.isNullOrEmpty(dateString), "Date [" + dateString + "] is empty of NULL!"); Split it into two checks, one for null and one for empty, ...


4

"A mess" is the first thing that comes to my mind. Why don't you just use a loop over the various formats? If you want to introduce a special guard (like the string length), create a parser objcet, which implements an appropriate check. Something along the lines of interface DateParser { boolean isApplicable(String in); LocalDateTime parse(...


3

Input validation The input validation is missing. If the user enters a letter, the program fails with InputMismatchException. An approach is to catch the exception, output an error message, and then either exit or ask the user to try again. Few other cases to cover: For y=0, the division will throw an ArithmeticException, so a second validation is needed in ...


3

It would be best to codify the various operations in a separate function. This limits the opportunity for error and eliminates the redundancy of the System.out.println("Result: " + a); statements. private static int applyOperation(int x, int y, int op) { switch(op) { case 1: return x*y; case 2: return x/y; case 3:...


3

Whoever says your code is not following OOP principles should continue by explaining their opinion about the shortcomings. As I see, it's class room code and it's intention is to teach a certain thing (JavaFX I assume) so it is acceptable to skip certain OOP aspects if it makes teaching the subject matter easier. When you want to teach OOP concepts, don't ...


2

I will point out one thing as it relates to OOP. You can potentially run into issues when you extend Pane. If you are going to extend Pane, make the class final. public final class ClockPane extends Pane The other route is not to extend Pane. Using that route, you can create a method that returns the Clock as a Pane. Clock clock = new Clock(..,..,..); ... .....


2

private int[][] toMatrix(int[] arr) { Don't shorten names just because you can. if(validConversion(arr)){ This does not need to be an extra function, actually, especially if you drop the "1" special case. An array of one item can technically be converted to a matrix with one item...it's just not much of a matrix. int matrixSize = (int) Math.sqrt(...


2

We could evaluate the square root just once: int width = (int) Math.sqrt(arr.length); if (width * width != arr.length) { // not square - invalid return null; } int height = width // not really needed, since we know matrix is square It's not clear why you reject arrays of 0 or 1 elements, so I removed that test. We should consider throwing an ...


2

Edge case 1 String result = getTargetString("Java is class-based", "Java", "class-based"); I would expect the result to be "is", but it is empty. This is because replaceAll("[^a-zA-Z]+","") removes the dash in class-based so the keyword doesn't match. Same for numbers: String result = ...


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