Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

putting a method into a String Buffer

 
Valarie Brandt
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • 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 ");
}
 
chi Lin
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
I don't understand what to code to access the methods that will bring in the information.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic