• 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
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

putting a method into a String Buffer

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to call a method in a string buffer Obviously I am doing something wrong but I can't tell. Maybe I have been looking at it to long but any suggestions would gretly be appreciated.
public void processLawn() throws Exception
{
Lawn lawnQuote = new Lawn();
getLawnSize(lawnQuote);
getNumberOfPayments(lawnQuote);
displayPaymentSummary();
System.exit(0);
}
public void displayPaymentSummary() throws Exception
{
StringBuffer sb = new StringBuffer ();
sb.append("Your lot size is ");
sb.append(getLawnSize(lawnQuote);//If i do it this wat I get cannot
//resolver variable lawnQuote and I get void type not allowed here.
//or
sb.append(lawnQuote.getLawnSize());//If i do it this way I get the
//error cannot resolve variable and its calling lawnQuote a variable.
//but lawnQuote is not a variable it is my object. It is instaniated
//in an above method and the above method calls the String Buffer
//method.
sb.append(" and you will be making ");
}
 
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
from the code, first thing I observed,
lawnQuote is declared inside processLawn() method, it became local
object reference, therefore can't be accessed from displayPaymentSummary().
 
Valarie Brandt
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The assignment required that I instaniate a Lawn object in the top-level control method which is the process lawnMethod. hOw do I call the methods in the display method?
thanks
 
chi Lin
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try


Lawn lawnQuote; // declare here
public void processLawn() throws Exception
{
lawnQuote = new Lawn(); // instantiate here
. . . . .
}
public void displayPaymentSummary() throws Exception
{
StringBuffer sb = new StringBuffer ();
sb.append("Your lot size is ");
. . . . . // access here
}

 
Valarie Brandt
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand what to code to access the methods that will bring in the information.
 
reply
    Bookmark Topic Watch Topic
  • New Topic