You can use an AtomicLong in a loop, certainly - but it doesn't do any looping for you. Similarly, you can use a local variable like "int i = 0" in a loop, but the variable doesn't do the looping for you.
Royal Summers wrote:So, I have a homework assignment and I have to look at some code and find a bug and fix the code.
Royal Summers wrote:
Do you have an idea of what this comment is trying to tell? Does the counter need to resolve to an odd number always?
posted 3 weeks ago
Here are the Directions:
Now that you have learned about how to debug an application in Spring, it's time to put that knowledge to work. In this Hands-On exercise, you will locate the source of the error in the MVC web application provided for you below. The goal of this project will be to fix the problem with the following program. The IDs are not generated as expected. The goal of generating new IDs for each message was to ensure the IDs could only be odd numbers (i.e., 1, 3, 5, 7, etc.). Please zip your project directory and upload when you are finished. This Hands-On will be graded, so be sure you complete all requirements.
Bug recognition: The cause of the bug must be identified.
Bug Fix: The bug must be removed from the application, such that the application operates as intended.
Create a new STS project called "lesson-9-project-part-1". Ensure that the package location is com.example.demo. Then, create a new class called GreetingController that contains the following content:"
The code that was provided was the first time the AtomicLong was introduced. I did research and didn't see AtomicLong having iteration functionality but I thought that I would post my question just to confirm my saneness.
Is there a reason why you think you need iteration functionality in AtomicLong? This sounds a bit like asking why the car's steering wheel does not have braking technology.
posted 3 weeks ago
So, I asked if AtomicLong 'loops' due to the fact when I Searched for it on the Internet I saw nothing of it looping which appears that a loop would be required in order to determine if the ID's were odd numbers per the Assignment. So, since I understand how a car works, I would never pose that question but since I had no clue how AtomicLong works then I posed the question just for confirmation.
Royal Summers wrote:So, I asked if AtomicLong 'loops'...
No, it doesn't loop. Because AtomicLong isn't a loop, but an object, which represents long value, a number in simple words. If you want loop, you need loop (sounds silly, but that's what it is). Numbers can be used in a loop though.
Here are two loops, one contains primitive number, while the other AtomicLong object.
They both print the same:
I don't know what else to add here, unless I completely misunderstanding you.
Royal Summers wrote:. . . ": the repetition . . . a specified number of times or until a condition is met" . . .
I don't think there is any need for there to be a specified number of times or until a condition is met; iteration simply means repetition and it is possible for it to go on for ever. That is of course the archetype of a program gone wrong.
posted 2 weeks ago
Thanks all for your input. I wasn't familiar with this Method and just needed to confirm whether or not I had to add a loop or if this Method did it.
Again, thanks for your time and input!
if you think brussel sprouts are yummy, you should try any other food. And this tiny ad: