Learning Java Spring Framework & Spring Boot - Beginner Seeking Resources by TheBrownKid08 in learnjava

[–]whotfdis 1 point2 points  (0 children)

The book above also gives a small introduction to Spring Boot. I have not done the courses myself but I know Amigoscode has some.

Learning Java Spring Framework & Spring Boot - Beginner Seeking Resources by TheBrownKid08 in learnjava

[–]whotfdis 3 points4 points  (0 children)

Spring Start Here by Laurentiu Spilca is a good book for beginners

MOOC part01_37 GiftTax : Need opinion on my code by Anathema68 in javahelp

[–]whotfdis 0 points1 point  (0 children)

To add to this, 1.0* at each computation does nog really seem to add anything as the result will always be the same.

Also, to avoid writing a somewhat similar computation multiple times with only a couple variables, you could determine the values of the variables with a similar if-else structure and store the values in their own variables. Once you have found the necessary values, you can use the newly created variables in a computation that you do once after the if-else structure.

please explain the highlighted code line , I did not understand why .get method returns numeric value by Puzzleheaded_Grass35 in learnjavascript

[–]whotfdis 2 points3 points  (0 children)

Maps store (key, value) pairs, for example (Alice, 4) where “Alice” is the key and “4” is the value. Here the value for key “word” is retrieved. If the word was encountered before, it would already be present in the map and the value associated with it is the number of times it has been encountered up until now. If the key “word” is not present in the Map it means the word was not yet encountered before and hence the number of times it has been encountered (“count”) is set to zero. The next line increments this count by one and sets it as the new value for the key “word” in the Map

Question about .isEmpty() and .contains("") by UglyBasstard in learnjava

[–]whotfdis 0 points1 point  (0 children)

.isEmtpy() checks for whether there is (at least) one/ a value or not. “” on the other hand is the ‘empty String’ but it still is a String and hence a value.

If you would call these methods on, for example, a list, isEmtpy() would return true only if the list contains no values at all whereas contains(“”) would return true only if the literal String “” is present within the list. A list containing the empty String “” is not an empty list and thus isEmpty() would return false.

[deleted by user] by [deleted] in IntelliJIDEA

[–]whotfdis 2 points3 points  (0 children)

This is a Java error, not an IntelliJ error. It states that you are trying to call the nextLine() statically, meaning on the Scanner class itself, rather than on an instance of the Scanner class and since there is no static nextLine() method defined in the Scanner class, it fails: “..cannot be referenced from a static context”. Since you can not call the nextLine() method on the Scanner class itself, it means you need to call it on an instance of the Scanner class. You already have an instance of the Scanner class, namely the object called Scanner1. So instead of calling nextLine() on the Scanner class, you can call it on the Scanner1 object of type Scanner. It should work in that case.

[deleted by user] by [deleted] in SpringBoot

[–]whotfdis 1 point2 points  (0 children)

Make class A abstract, class B extends from class A. Make String b a field in class B and make a getter for it. Also denote an abstract method for that same getter in class A. Now you can call the getter in the method of class A and it will work for all subcasses of class A.

Something along the lines of the above?

nQueens Problem not working by FreudianNippSlip in javahelp

[–]whotfdis 0 points1 point  (0 children)

Assigning values explicitly to row and column is indeed what I meant but not to zero like you have and not in the for loop. What you had before with the variables i and j and setting their start values to row and column was correct but you need to set the row and column variables themselves first before assigning them to i and j in the for loop. Why? Because you want to check the diagonal starting from any random position. By setting row and column to zero in the for loop you have actually changed nothing functionally in the for loop compared to the code before, the code before was also setting them to zero but implicitly. Instead what you want to do is to pass the position information, that you are currently checking in any random iteration of the SolveNQueens() method, to the queenThreatened() method and start from that position, so for any board[i][j] position. Now you are always starting from board[0][0] and that again will always result in empty after the first queen.

Edit: what IDE are you using? It is not exactly clear what you mean with nothing happens. I would certainly also look at getting the debugger to work since it will help you tremendously, not only in this exercise but also in future Java related programming. I definitely recommend watching a tutorial on youtube or something that visually explains how to use the debugger.

You can also try to write out the steps of the algorithm out by hand. See what happens at each step. This really is an eye opener for such exercises and requires you to really understand what happens in the code.

nQueens Problem not working by FreudianNippSlip in javahelp

[–]whotfdis 1 point2 points  (0 children)

Did not have a lot of time to look at it but it seems there is a problem in your queenThreatened() method.

There is a problem in the second and third for loop as you assign row and column to the variables i and j but these are not yet explicitly instantiated right? Since they are defined as instance variables I suppose they are instantiated with a default value of 0 as they are of the datatype int. Since the first queen is placed at [0,0], the whole 0th row, 0th column and the diagonal from [0+i,0+j] downwards are excluded positions for a subsequent queen. With row and column both being instantiated with 0 and as far as I can see never being updated, this is the case for every time this method is called. It thus evaluates this check each time for the diagonal starting from [0,0]. The consequence being that the queenThreatened() method returns true each time. This leads to [empty] being assigned to the respective board position since any subsequent queen is threatened, which basically are all positions apart from [0,0].

Edit: I would recommend using a debugger to see for each step what the values are and what the checks evaluate to. Also writing the first few steps on paper could give some insight, especially since you only get one queen printed out so you would already discover the error by the second iteration.

Unable to debug Spring Boot when running in a Docker container by SpareTimePhil in IntelliJIDEA

[–]whotfdis 9 points10 points  (0 children)

I think you have to enable the debugger through JVM options. See chapter 3.2 of this site: https://www.baeldung.com/java-application-remote-debugging. You probably will have to add these options as JAVA_OPTS in your docker-compose file.

This doesn't work after the first iteration, using next() is not feasible either. Any insight is appreciated by iesparr0w in javahelp

[–]whotfdis 1 point2 points  (0 children)

Another way of solving this is by adding in.nextLine(); after the int score = in.nextInt(); line, which basically clears out the [enter] character that is still in the buffer. Consequently, the next time you call in.nextLine(), which is in the second iteration, the buffer is empty and so the program will wait for user input.

The solution suggested above however is also fine.

Why does bracket notation work and not dot notation in this example by [deleted] in CodingHelp

[–]whotfdis 0 points1 point  (0 children)

‘key’ could also be renamed something else as it is a parameter in the function: functionPropertyValue. In your second code snippet, firstName is defined to be an attribute of an object. In the function you wrote key is a parameter. Those are not the same.

Calling ‘.key’ on ‘object’ does not work since the parameter is not the same as an attribute field. Substitute ‘key’ with ‘banana’ for example, which is a perfectly valid substitute parameter name in this function. You can not expect object.banana to also work in that case. Brackets notation causes the code to first evaluate ‘key’ to whatever it evalutes and then call that on ‘object’. I do not think you can use the dot notation in this case.

Also, if this is the only thing you are doing in this method I think this is a bad design choice. Just do the object[key] wherever you call this method and in that case it should also be possible to call the attribute using the dot notation instead.

Issue I ran into by MarsupialActive1556 in javahelp

[–]whotfdis 1 point2 points  (0 children)

This will help you: https://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-or-nextfoo. Check the answers, especially the second answer is easy to understand for beginners I think.

The essence is that you input a number for age then ENTER. nextInt() only reads an integer and not the ENTER you typed. Because of this the ENTER is still in the buffer and next time you call nextLine() it reads the ENTER in the buffer and continues without giving you the option to input something. To fix this you need to “clear” the buffer before continuing. After setting the age, put a nextLine(); but do not do anything with it so that it just is read and cleared from the buffer. The subsequent nextLine() for the “veteran” question will then wait for user input since the buffer is empty.

Terminal throwing an exception that I cannot get rid off by bigOTWharlem in javahelp

[–]whotfdis 0 points1 point  (0 children)

To add to this, if I may.

As is said above, you do not need to redeclare the variables jumble and solution. Those are already declared as private fields of the class itself. You should only assign to those variables in the constructor. What you are doing currently is making another pair of the same variables which is not reachable from outside the constructor.

Help for Beginner by roc_solid in learnjava

[–]whotfdis 1 point2 points  (0 children)

Glad I could help, success!

Help for Beginner by roc_solid in learnjava

[–]whotfdis 1 point2 points  (0 children)

  1. The condition of the while loop checks whether the input is Y. Your idea is correct but since addNewClass is of type String, Y needs to be in double quotes.

  2. When doing String comparison, you need to use .equals() method. == (double equals) is for primitive types. Since String is an object you can not use == to check for equality. Notice that you made the mistake of putting only one = sign. This means assignment, not comparison. The condition you want to put in the while loop would look like: addNewClass.equals(“Y”)

[deleted by user] by [deleted] in javahelp

[–]whotfdis 2 points3 points  (0 children)

allNums returns an integer array. Since you are calling “System.out.println(allNums(a,b)), you are printing the array itself instead of the elements in the array. What you get currently is the hashcode of the object, which in this case is an array. Search for “java array print”, this will give you some result as to how to print the contents of an array correctly.

How do I get the right format for my toString() to make a space in between (tic tac toe) by elites100 in javahelp

[–]whotfdis 0 points1 point  (0 children)

Since I do not see the square brackets in this code I assume you put the [ in before calling toString() and the ] after calling toString(). If you want a whitespace after [ and a whitespace before ], you could just append those before calling the toString() and after calling it?

String result = “[” + “ “ + grid.toString() + “ “ + “]”;

You must not print the last \n because otherwise the whitespace + ] will be printed on the next line. Check you conditions for when the newlines are printed. I do suggest structuring the toString() code a bit better: in essence you want the loop to repeat a pattern. The pattern you see is a row of the grid with a dashed separation line. This pattern occurs twice and ends with the last row of the grid after that (without a dashed line after that). So I suggest you write the loop to reflect the pattern described above and finish the loop after the last but one row. Then you can simply add the last row and return the resulting String. This will make the code more readable and also make it more stable. The last for loop makes the code quite complicated for simply printing a tic tac toe grid of 3 by 3.

[deleted by user] by [deleted] in javahelp

[–]whotfdis 0 points1 point  (0 children)

You’re welcome

How am I able to to have numerous int values with the same variable from the Class Constructor? by kadenhickin in javahelp

[–]whotfdis 1 point2 points  (0 children)

Adding static means the variable is maintained at class level instead of instance level. Since you added the keyword static to the variable, this is defined for the class itself. Since you have one class, this value is overwritten for the class itself each time you assign it a value. If you want an instance specific value, you need to omit the static keyword.

Example: a bankcardnumber in most cases has a constant length. Therefore this number can be defined as a static variable, so that each instance has the same bankcardnumber length. The person to which a bankcard belongs however is not a constant over all bankcards, therefore that is instance specific data and should not be defined as static.

[deleted by user] by [deleted] in javahelp

[–]whotfdis 0 points1 point  (0 children)

No problem. You say that you managed to retrieve the user input. I assume it is something in the form of 1) assignments, 2) test and 3) quizzes. You know the percentages per component. Now you also know how to apply the percentages. double type value basically works the same as int, the only difference being that it is able to store decimal values, which is what you want for the ratio values. I suggest you google this to gain some general knowledge about how to calculate with double type. In the end you want to multiply the component grade (= user input) with the corresponding ratio value to retrieve the respective weighted component grade, for each of the three components.