• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

how to bind values in Object using multiple inner for loop

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Problem:

if I print values in loops it work fine but i want to get all values corresponding to ids' how do i get this.please anyone suggest me how to do that?.


career id ---------have many pathid------------>PathID ---------- each path id have 4 program id-------------->program id ------------each program id have course name----->course name

I got courses name using

// for CareerId
For(){
for(){//find path id for each careerid

for(){//find 4 program id for each pathid
for() {// find course name for each set of 4 program id

}


}
}


}
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

shivmaruti singh wrote:if I print values in loops it work fine but i want to get all values corresponding to ids' how do i get this.please anyone suggest me how to do that?


I hate to say, but that's a very vague description of a problem; and I'm afraid your "pseudo-code" isn't much better:

1. UseCodeTags (←click). Even for pseudo-code, it's much better, because we get to see the indenting.

2. Why not deal with each problem separately, and write a method for it? Eg:and then do something similar for your other three "loops".
Then in your main() method you might have something like:You could also do it with arrays, but Lists are easier.
And if you have classes for Career, Path, Program and Course, you could use those instead.

HIH

Winston
 
shivmaruti singh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Thanks winston for help and sorry for my vague post. I have done list implementation as you suggest me . problem is that in last I want detail as I show in eg store as a object and use to print in another class as report . eg.

career id : 101
Bachelor in Art
Master in Art


career id: 103
Bachelor in Biology
Master in Biology
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

shivmaruti singh wrote:...problem is that in last I want detail as I show in eg store as a object and use to print in another class as report . eg...


And our problem is that we have no idea what you've done, or what you're working with.

Do you have classes for Career, Path, Program and Course? Because it would make things a lot easier if you do.

Either way, show us what you've written, and where you're running into problems (including the classes I named above, if you have them). It'll be a lot easier to help you then.

And don't forget to UseCodeTags.

Winston
 
shivmaruti singh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes i have classes career id and path id, program id, and want to collect all career id with respect to their data and print that out side the all loops . use these as datasource for report


all place where i use System.out.println() function i want collect all data and print on report career id wise.
 
Bartender
Posts: 2237
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure you need nine(!) methods that do exactly the same thing?
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

shivmaruti singh wrote:yes i have classes career id and path id, program id,


Those don't sound right to me, but from looking at your code, I suspect its just the names that are wrong.

An 'ID' is simply an identifier, so it's probably just an integer or a code of some sort.
What you want is a Career (or Path, or Program) object that contains ALL the things related to a single Career (or Path, or Program).

Now maybe that's what you have, but you still haven't shown us what they look like. Just so we don't get inundated, show us the code for one of them: eg, PathID, and then we can go from there.

You've also introduced something new - a 'dao' object - which you didn't tell us about (but I suspected was there all along ), viz:
  List<CareerId>list2=dao.combination(p1, p3, p2);

However, things are looking a lot better now, so I can advise you on a few things:

1. Use "for-each" loops (I think the official name is "enhanced" for loop) when iterating Lists. They're much simpler, viz:instead of:
2. Have your methods return a List istead of trying to link them all together externally, eg:
  private List<PathId> eightCombination(List<CareerId> list8) {
instead of:
  private void eightCombination(List<CareerId> list8) {
Then your methods will be a lot more self-contained.

3. Have each method take a single object, not a List. Ie:
  private List<PathId> eightCombination(CareerID career) {
instead of:
  private List<PathId> eightCombination(List<CareerId> list8) {

Then your implementation might be as simple as:the only difference is that you'd have to call it once for each CareerID object and aggregate the returned PathIDs into a single List, viz:Do you see how it works? You could even write a method to do that (the aggregation) if you want.

Right now you're making your methods do far too much at once, and because they all return void, you have no way of connecting them together (at least, not easily).

Remember:
  • One method, one - and ONLY one - task.
  • Never write a method that returns a void if it can usefully return something else.
    In your case, ALL your methods can return a List of whatever they're trying to collect, and you can worry about the business of connecting/aggregating them later.

  • HIH

    Winston
     
    reply
      Bookmark Topic Watch Topic
    • New Topic