Im tried to passing 2 Objects defined (Transaction with one attribute "amount") to another method that will receive the list of Transaction
This is the main:
public class Test {
public static void main(String[] args) {
// Here is when the Transaction was sent twice with differents amounts
BankAccount saving = new SavingAccount("Raul", 1000d, new Transaction(500d), new Transaction(-500d));
}
}
This is the Object Transaction
class Transaction {
private Double amount;
public Transaction(Double amount) {
super();
this.amount = amount;
}
public Double getAmount() {
return amount;
}
public void setAmount(Double amount) {
this.amount = amount;
}
}
and This is the Bank class
class BankAccount {
private String name;
private Double amount;
public BankAccount(String name, Double amount) {
super();
this.name = name;
this.amount = amount;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Double getAmount() {
return amount;
}
public void setAmount(Double amount) {
this.amount = amount;
}
}
and finally the SavingAccount will do some operations with the List of transactions
class SavingAccount extends BankAccount{
public SavingAccount(String name, Double amount, List<Transaction> transaction) {
super(name, amount);
// Do something with the list of transactions
}
}
My first solution was to create a List of type Transaction and pass to the method and it Works, but my solution was rejected...
public class Test {
public static void main(String[] args) {
List<Transaction> transaction = new ArrayList<Transaction>();
transaction.add(new Transaction(5000d));
transaction.add(new Transaction(-5000d));
BankAccount saving = new SavingAccount("Raul", 1000d, transaction);
}
}
How can i do to maintain the send of that objects as parameters without define a ArrayList first?
ArrayList)