This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!

Junilu Lacar

+ Follow
since Feb 26, 2001
Junilu likes ...
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
Columbus OH
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 Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Junilu Lacar

Line 45 is your problem. I don't see any code prior to that line that would add anything to summationSet so the expression j < summationSet.size() will immediately return false since summationSet.size() would be 0,  thus your for-loop body will never be executed. This would explain why you don't see anything when you print out summationSet.  

BTW, why would you call that object "summationSet" when in fact, it's a List? Name things properly so that your code doesn't mislead people who read it.
14 hours ago
What is your question?

Also, your code is quite difficult to understand so providing less code and a more specific and detailed question would be better.
15 hours ago
This is not valid code:

You can't assign a value to a parameter like that. Besides, there's no need to do that. The value of the parameter will come from the caller of the method.

Also, when applicable, prefer declaring a parameter like that as a List instead of ArrayList. An ArrayList implements the List interface so declaring the parameter as a List makes your program more focused on the API/behavior as defined by List rather the specific implementation of that behavior. When you declare the parameter as a List, you can still pass in an ArrayList but you can also pass in any other implementation of List.
1 day ago

I wrote:The code you wrote will never stop looping because you used an assignment (=) instead of a comparison (==)

Well, unless you use break to exit the loop, which you did. Doing that is poor form, however. Use the break statement sparingly and if at all possible, avoid it.
1 day ago
Welcome to the Ranch!

This code compiles but is most certainly not doing what you intend for it to do:

1. NEVER try to compare a boolean variable with a boolean literal like true or false. It is both unnecessary and error-prone.

2. A better way to write that logic is:

3. An even better way is to use an expressive name so that your intent is clear:

The code you wrote will never stop looping because you used an assignment (=) instead of a comparison (==)

The expression (x = true) assigns true to the boolean variable x and evaluates to the assigned value, true. So, your while condition will always evaluate to true, no matter what you do to change the loop variable in the body of the loop.
1 day ago
Ok, if making assumptions is part of the problem, then here's what I would answer:


1. All types are classes, not interfaces, and the given code compiles.

2. The hierarchy is as follows:
Object <- Item <- Food <- FastFood <- Hamburger

3. Each class adds at least one non-private method that is not in its superclass.

With these assumptions, using the reference food2 would allow only accessible methods in type Food to be called on the object whereas using the reference h would allow you to call all accessible methods of the type Hamburger
1 day ago

Tim Holloway wrote:So don't avoid recursion just to be "efficient". Only be efficient when you detect that you're being inefficient. The recursive solution is often easier to read and understand, and these days, it's the humans that are the expensive part of the system.

A thumb is not enough to voice my support of this thought so have a cow instead.
1 day ago

Daniel Andersson wrote:My thinking is that line 2 and line 4 for the question asked is just there to confuse you or make you think.

And what about this:

Daniel Andersson wrote:If we assume that FastFood is a superclass of Hamburger. What would be the difference between using the object food2 and the object h?

Was that how the question was formulated, too? Because the fact that FastFood is a superclass of Hamburger has nothing to do with the food2 and h variables either.

And regarding assumptions, I have been doing this long enough to know better than to make assumptions regarding anything about programming. If you want a meaningful discussion, please provide meaningful details.
1 day ago

Stephan van Hulst wrote:The only tools you need are a pencil, paper and an eraser.

And about 3 pounds of gray matter.

When you have a description of the problem domain, you can start by writing down the nouns of the description, and how they interact with each other through verbs. You can then eliminate terms that are not related to the problem, or are too simple to be represented by a class.

That's how many people are taught design. My experience, however, is that this process leads to confusion and over-engineering. I like to start with tasks and description of outcomes. Then work my way backwards, identifying information I need to complete those tasks, then figure out how to arrange that information around the tasks and then organize the tasks+information around various entities that might collaborate with each other.

Line 3 declares a variable of Food type, not FastFood.  You never mentioned anything about a Food class and where, if at all, it fits in the hierarchy. Please be careful about such details going forward.
1 day ago
@KR: that example run does not conform to OP's given requirements.

@OP: next() or nextline() should suffice for your needs. You'll need to assign the token you read in with either method to a String variable and then parse that String to its individual characters. Look through the String API JavaDocs to find a suitable method that can give you back an array of char for a given string value.
2 days ago

Joe Farmer wrote:How do i create an object model an establish a small set of test data? and establish a set of test cases ?
can someone help me with this?

My approach would be somewhat backwards: start by identifying tasks / things you want to be able to do (e.g. register books, make inventory lists, find by ISBN, etc.) then look at what information you have that would be related to these activities, then identify ways to test whether a user is able complete a task. Only when that context has been established would I start trying to figure out how to organize the information around objects that would be used to complete a task.

Give that a shot and see what you can come up with then come back and ask detailed questions.
That code will not even compile. You cannot have any private declarations inside a method or constructor.
3 days ago
The problem is primarily is a lack of communication and feedback. You should be inspecting and adapting the work in progress more often. You can codify your understanding in the form of test cases. You can demo work in progress more often. Also, the architect giving you requirements is a process smell. This suggests to me that your "stories" are more technical in nature rather than business-focused.

Shubham Rai wrote:Is there any way to find present capacity of ArrayList?

And by the way, the short answer to your question is no, the ArrayList class does not provide any method that will allow you to query the current capacity. As mentioned already earlier, the best you can do is to call ensureCapacity() to set the minimum capacity.
4 days ago