Soldato
- Joined
- 5 Dec 2003
- Posts
- 2,716
- Location
- Glasgow
Hi, just trying to learn Java and do a little project in it and i've come up against a brick wall, wondering if someone here can help me out.
I've managed to create a method to insert an array into a LinkedList.
Now i'm trying to make a second method to write it out to the screen again but i'm having trouble accessing the array elements.
Here is the code:
This runs okay but the output is rubbish and I expect that but when I try to change this line:
to something like
it gives the error cannot resolve Symbol.
I've managed to create a method to insert an array into a LinkedList.
Now i'm trying to make a second method to write it out to the screen again but i'm having trouble accessing the array elements.
Here is the code:
Code:
public class Transaction
{
List transactions = new LinkedList();
public boolean setTransaction(String transactionType, Double transactionAmount)
{
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
NumberFormat numberFormatter;
numberFormatter = NumberFormat.getCurrencyInstance();
Date now = new Date();
String nowFormatted = formatter.format(now);
String transactionAmountString = numberFormatter.format(transactionAmount);
String[] transactionArray = new String[3];
transactionArray[0] = nowFormatted;
transactionArray[1] = transactionType;
transactionArray[2] = transactionAmountString;
transactions.add(0, transactionArray);
return true;
}
public void getTransactions()
{
for(int i=0; i<transactions.size(); i++){
System.out.println(transactions.get(i));
}
}
}
This runs okay but the output is rubbish and I expect that but when I try to change this line:
Code:
System.out.println(transactions.get(i));
Code:
System.out.println(transactions.get(i).nowFormatted);