Emil Jennings

Ranch Hand
+ Follow
since Jul 09, 2010
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Emil Jennings

Now I guess I'm going for being banned but whatever...

Henry Wong wrote: As for your second case, you didn't show us the code, so we can't really explain what is wrong.

That is completely WRONG.  I was able to determine what the OP was having problems with using the code provided by the OP.  Based on this series of posts, answers from Henry Wong should be considered with a LARGE grain of salt.  Nuff said.
7 years ago

Henry Wong wrote:
Hint: Be careful to not confuse the assignment operator with the equality comparison operator. See your while loop.

Dude...that while loop isn't even needed, what kind of an answer is that?  This is why people get so frustrated with forums like this.  Random answers that don't address the real problem.  Unreal.
7 years ago
Good job Michael,

Consider this:

The difference it isRangeFound is merely a condition to be checked and doesn't require iteration (it's either true of false).

If there is no other description of the problem, the pseudocode in the flowchart you posted IS flawed because of the placement of parens is wrong and will never yield the desired results.
7 years ago
Henry...you could be a little more helpful, such as the flow chart only depicts one loop.  I know the idea of these forums is not to spoon feed but come on...

Michael - The symbols of the flow chart and the arrows indicate what they are for.  The fact that the flowchart has one place that has arrows going into and out of (1 to 1000) is the indication that only one loop is needed.  Everything between Begin and isRangeFound = False are simple processes (assignment statements).  You should revisit program flowcharting and pseudocode.  The flowchart has the for loop, which your code has.  Does the flowchart have a while loop in the for loop (diamonds are decisions, not loops)?

That middle part in the flow chart is written wrong, it should be isRangeFound = "false" and (pie >= 3.14159265 and pie < 3.14159266) parens set up order, again revisit flowcharting and pseudocode.

Basically, the flowchart is correct:
Loop 1 to 1000
variable assignment
variable assignment
variable assignment
one compound condition (hint it's above)
three assignments if condition is true, none if condition is false
next condition for output

Straight up answer about the parens - in the 2nd condition (i=200, 500, 1000) they are unnecessary.  And they are wrong in the first condition.  In the first "diamond" each condition is in it's own set of parens, which means they might as well not be in any because that means three conditions must be true:
isRangeFound = "false",
pie >= 3.14159265, and
pie < 3.14159266,
when in fact only two conditions must be true:
isRangeFound = "false", and
(pie >= 3.14159265 and pie < 3.14159266)

(isRangeFound = "false") and (pie >= 3.14159265) and (pie < 3.14159266) means isRangeFound must be "false" and pie >= 3.14159265 and pie < 3.14159266 which will never be true because pie can't be >= 3.14159265 and < 3.14159266 at the same time.  These are three unique conditions.
(isRangeFound = "false") and (pie >= 3.14159265 and pie < 3.14159266) means isRangeFound must be "false" and in addition to that pie >= 3.14159265 and pie < 3.14159266.  The placement of the parens states that isRangeFound = "false" is one condition, while (pie >= 3.14159265 and pie < 3.14159266) is one compound condition where each of the two conditions must be true for the entire condition to be true.

You wrote the middle part correctly according to the flowchart as
(isRangeFound = "false")
and (pie >= 3.14159265)
and (pie < 3.14159266)

Unfortunately the flowchart is wrong and it should state
(isRangeFound = "false" and (pie >= 3.14159265 and pie < 3.14159266)

Make sense now?
7 years ago
Part 2 - Why you need them?  Technically you don't "need" abstract classes.  But for Buildings, which is more ideal - you have to code every House, Mall, Jail, Restaurant with numberOfFloors, numberOfDoors, numberOfWindows or you simply have every House, Mall, Jail, Restaurant extend Building which will ensure they all have numberOfFloors, numberOfDoors, numberOfWindows simply by inheritance.

Interfaces aren't "needed" either but they do provide something of a guarantee.  With the calculator example, if you implement my interface which says you must implement an add method that returns an integer result, I am at least guaranteed that the result given is an integer.  Again, your implementation of add may actually subtract, but at least the returned answer will be of the data type I am expecting, which reduces errors.
7 years ago
My overly simplistic way of thinking is this:

An interface says the if you implement it, you must do certain things but how you do them is up to you.  For example, if I create a calculator interface I will specify that in order for you to use my interface you must implement methods add, subtract, multiply, and divide.  You may implement the add method to actually subtract (which will create a lot of discontent) but it's your implementation.

An abstract class defines an idea.  An Animal can be abstract because an "animal" can be considered as not having a physical existence.  An animal does have attributes associated with the idea - an animal has a specific number of legs, an animal has an age, an animal has weight, an animal has a specific diet.  So you create an Animal" with those attributes.  Then you create animals by extending Animal, such as a Giraffe.  Then the Giraffe has all of the attributes of an Animal plus those specific to a Giraffe, such as hasSpots().  Similarly, a Building is an abstract thing while houses and malls are concrete buildings.  The abstract class holds what is common among buildings while houses and malls have the attributes of Building plus the attributes that make them houses and malls.
7 years ago

...it gives me the very last value of pie within that range (at the very last iteration - 1000)

Yes, it does because you never ask isRangeFound.

7 years ago
Hold on a second my friend...stop coding for a minute.

You have to display the value of pi at the 200th, 500th, and 1000th iteration.
You also have to display the number of iterations it took for pi to have a value between 3.14159265 and 3.14159266.

When you start your 1000 iterations, you have to see if isRangeFound for pi (which when you start it is not).  But once pi isRangeFound you save the value of pi and the iteration that value was found at and make sure the program knows isRangeFound occurred.
7 years ago

The break statement in Java programming language has the following two usages −

   When the break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop.
   It can be used to terminate a case in the switch statement.

When you break at the 339th iteration, the loop is terminated.  So, if pie is within the range you're looking for then the next question you should ask is if you've saved i and pie the first time pie is within the range.

Make sense?
7 years ago
Might I suggest that there is nothing wrong with your string builder, it works just fine...when it executes (hint hint). Since you append letters to StringBuilder sb while (allTrue == false), what happens after you set allTrue to true? Or more importantly, what DOESN'T happen?
8 years ago
In the first iteration at line 7 the value of x is 3, so line 9 is true and it prints a. Line 13 executes and the value of x becomes 2, then - is printed. Line 16 is true and b c is printed. Line 20 is false and the loop starts over.

In the second iteration x is 2 so line 9 is false. Line 13 executes and the value of x becomes 1, then - is printed. Line 16 is false. Line 20 is true and d is printed and the value of x becomes 0. And back to the loop condition.

In the third iteration the loop condition is met and the loop exits. If the second x = x - 1 wasn't coded the loop would have executed one more time and the additional - would be printed after the d.
8 years ago
The configuration property hibernate.hbm2ddl.auto has four values:

validate: validate the schema, makes no changes to the database.
update: update the schema. Be very careful (read avoid) using update in production.
create: creates the schema, destroying previous data.
create-drop: drop the schema at the end of the session.
The problem is with:

I mistakenly thought that by querying the database and getting a single item in the result set meant that I could update it with the stuff in foo (session.getNamedQuery, session.saveOrUpdate, the session know what I want by "magic" right?).

So instead, doing something like

And that takes care of the org.hibernate.StaleObjectStateException. Hope this helps others.
Hi Dave,

I'm trying to get data from a fixed length flat file and update the database with that data. So...

The stack trace I'm logging is:

Right now I'm looking at the generated HQL to find test.stuff.Foo#0, and doing the debugging as you suggested.
OK, I understand the exception itself, but not why it's being raised. Basically what I have is a couple of tables that I need to update from flat files so I build a list of objects from the flat file then loop through the that list to retrieve the database by an ID using a for-each loop. Since I am testing, the result set only has six cases in it and updating the first one seems okay, but when the loop iterates the second time and the new result set is attempting to be populated I get the exception. I would have expected it on a save or update, but not on retrieving the results of a named query. So, for instance...

Debugging shows the exception occurs at line three of the second iteration.
I hope this makes sense. TIA.