| Author |
putting a method into a String Buffer
|
Valarie Brandt
Greenhorn
Joined: Oct 03, 2003
Posts: 24
|
|
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
Joined: Aug 24, 2001
Posts: 348
|
|
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().
|
not so smart guy still curious to learn new stuff every now and then
|
 |
Valarie Brandt
Greenhorn
Joined: Oct 03, 2003
Posts: 24
|
|
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
Joined: Aug 24, 2001
Posts: 348
|
|
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
Joined: Oct 03, 2003
Posts: 24
|
|
|
I don't understand what to code to access the methods that will bring in the information.
|
 |
 |
|
|
subject: putting a method into a String Buffer
|
|
|