![]() |
Help understanding toString()
I am trying to get out put which looks like this:
Code:
transaction# 0 Error: Tue Nov 16 16:47:15 EST 2010 bye : AMOUNT : 300.0Code:
bye Code:
public String errorDescription() { Code:
transactions[numTransactions] = new TransferTransaction(accountNumber, accountNumber, amt, balance); incrementTransactions();Code:
for (int i=0;i<numTransactions;i++) { |
In your errorDescription() function, just simply add the word "bye" inside the double quotes of your return string
Code:
return "Error: " + today + " "+ errorDescription() +" bye : AMOUNT : " + amount;You can get rid of the System.out.println line and the toString() line. You don't need that. All you are doing is concatenating literal strings and variables via the "+" operator, so you can type whatever inside the double quotes and they'll show up. |
Yes thanks I know this thanks. But what I am actually trying to do is have it call upon 2 different things within the method. for instance
if(balance > 0){so I am unable to just put "bye" within there. This class is being called by another class that is why to string is used. |
Just make a local string variable and set the value of the variable inside your "if" conditional statement.
AND, in your return statement, add the variable, which will display the value that was set by your "if" conditional statement. Code:
// make a string variable "msg" |
| All times are GMT +1. The time now is 07:51 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.