Reputation: 35
I am having issues passing the values of the paramarized construcor as an object in another class.
public class Client {
private String firstName;
private String lastName;
private long phoneNum;
private String email;
public Client (String firstName, String lastName, long phoneNum, String email) { }
}
public class Account {
private long accountNum;
private double balance;
private Client client = new Client(null, null, accountNum, null);
private Random random = new Random();
}
In the Account class it String, String, Long, String. It is taking the long value in the account class and putting it into the Client parameter. How do I pass the parameters I specified in the Client class?
Upvotes: 0
Views: 721
Reputation: 1294
Your Account
class should be like this:
public class Account {
private long accountNum;
private double balance;
private Client client;
private Random random = new Random();
public Account(long accountNum){
this.client = new Client(null, null, accountNum, null);
}
}
Upvotes: 1
Reputation: 332
Add getter and setter for Client in Account class.
Set the accountNum in Account class.
Then create a instance of Client
Client client = new Client(null, null, accountNum, null);
Then in Account class, set the client.
public void setClient( Client client )
{
this.client = client;
}
Upvotes: 0