java - How to Print out a particular way using nested loops with print writer -


i trying read file , print out information way

this current method

public class printimpl {  public void createreport(propertylogimpl propertylogimpl, realtorlogimpl realtorlogimpl, string filename) {     system.out.println("creating clean report..");     system.out.println("report complete -- located in file: " + filename);      try {          printwriter writer = new printwriter(filename);         linkedlist<property> propertylist = propertylogimpl.getpropertylist();         system.out.println("realtor log:");         realtornode listtop = realtorlogimpl.getlisttop();         realtornode temp = listtop;         iterator<property> iter = propertylist.iterator();         propertylogimpl.setpropertylist(propertylist);         property property = iter.next();          while (temp != null) {             writer.println(temp.getrealtor().getlicensenumber() + " " + temp.getrealtor().getlastname() + ", " + temp.getrealtor().getfirstname());              if (temp.getrealtor().getlicensenumber().compareto(property.getlicensenumber()) == 0) {                 writer.println("    " + property.getmlsnumber() + " "                         + property.getstreetadress() + " "                         + property.getbedrooms()                         + "/" + property.getbathrooms() + "$ "                         + property.getaskingprice() + " "                         + property.issold());                  writer.println("        " + property.getcity() + ", "                         + property.getstate() + ", " + property.getzipcode());                 if (iter.hasnext()) {                     property = iter.next();                 }             }          }         temp = temp.getnextnode();          writer.close();      } catch (filenotfoundexception ex) {          system.out.println("file not found");         system.out.println();     } } 

}

but thing is, gets stuck in infinite loop. suppose match realtor license number property license number. property linked list , realtor node thats linked list. im trying 1 node, , itterate through properties , print out properties under on realtor. switch next node , repeat. none of loops tried have worked. please help!

this file suppose like

cd4524521 snart, paul          1254294         246 wart street       2/3.0   $   456321.00    sold                      somewhere, co 54236            1683946       879  main st            2/2.0   $   646589.00                   somehwere, co 45726 

it that, realtor name , keep adding properties realtor, after there no more properties realtor, switch new realtor , keep adding properties one. thanks

temp = temp.getnextnode(); outside of while-loop. value of temp never changed. why infinite loop, while-condition temp != null.

also, i'd recommend think overriding tostring() method of property class or add method nicely formatted string representation of properties. code looks cluttered if start puzzling strings output in while loop.

@override public string tostring(){     return prop1 + "\t" + prop2         + "whatever" + somefield; } 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

angular - Copying node modules to wwwroot AspNetCore -