• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

toString() method for FORMULA class

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

In my current project there is a class defined as:
public class APPLIEDRATES {
....
...

public static final class FORMULA extends LinkedHashMap<LHSRATE, HashMap<String,RHSRATE>> {
private static final long serialVersionUID = -4754565974505570612L;
private FORMULA () {super(10);}
}
--
--
public static final class LHSRATE{}
public static final class RHSRATE{}
}

Please help me write toString() method for FORMULA class.

Please note that LHSRATE and RHSRATE hv toString() methods defined.
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

Hmmmmm. Well, toString() is generally used to provide a simple, readable snapshot of an object's state, handy for debugging or informal reporting.

Since we don't know anything at all about what any of these classes are or what they do, I'm finding it hard to imagine why you'd think we could be much help here.

So what would you like to see displayed if someone prints a FORMULA object?
 
amitesh kumar
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the reply.

as per my TL's suggestion first i've to call toString method of LHSRATE for each of the key values of FORMULA object then using a nested loop print values of RHSRATE.

something like

public String toString() {
StringBuffer sb = new StringBuffer("=========== Formula==============\n");

//define some iterator of FORMULA type
//loop all key for FORMULA
// call toStrind() method of LHSRATE
//append these to sb;
//loop all values for FORMULA
//loop keys of String name for RHSRATE
//append these to sb;
//call toStrind() method of RHSRATE
//append these to sb;
// ..

....




}
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so what part are you having trouble with?
 
amitesh kumar
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i've the rough idea abt the code. i'm not able to write the correct code. please help me i've hardly writtensome codes in core java collections api and this one requires Generics knowledge
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like you need to hire a programmer. We're got a "Jobs Offered" forum on this site you could use.

Alternatively, here is some useful documentation; note the link to Sun's generics tutorial at the bottom of the page. You've got some reading to do!
 
I think I'll just lie down here for a second. And ponder this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic