| Author |
Comunication between classes
|
Gustavo Siqueira
Ranch Hand
Joined: Jun 15, 2011
Posts: 94
|
|
Hello all!
I with doubt in question between class.
See code:
Class Principal.java
Class Conta.java
Class Cliente.java
As can view. I pass the name client of method (setNomeCliente) with for the method:
and after, display with:
The error that appearing how null. The that do?
|
 |
Daniel Marti
Ranch Hand
Joined: Jun 08, 2011
Posts: 37
|
|
Hello Gustavo
I would like you to pay attention to the parameter name in :
As you can notice you call the parameter nomeClienteNetwork, but you use the content of nomeClienteItau to set the "cliente" name.
What this means is, while you pass to this method the content of nomeClienteNewtork, what you will insert in the "cliente" attribute will be the content of nomeClienteItau, which is something i cannot see declared in any point of your code.
Should solve your problem.
Now for some nitpicking (hope you do not mind):
Your setNomeCliente() in the Cliente class should not have any interface with the user. A set method should only receive the parameter to set, [optional but desired] check if the parameter value is acceptable to be set to the wished attribute, and then set the attribute with the value of the parameter.
The similar problem exists in your titular method in Conta. It should be called setTitular or setCliente[preferable].
Also you do a c1.getTitular() in the System.out.printf but i can't see the declaration of that method anywhere.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
Some design problems there. You have a Conta class with cliente as a field. That is dubious. A Conta (account) does not have a cliente. A Cliente has a Conta. I think you ought to remove the cliente field from the Conta class. You should have a conta field in the Cliente class, however. You also have given your methods inappropriate names. a method called setNomeCliente ought to look like thisIf you are "set"ting a field, then there ought to be a field with a corresponding name. Your present setNomeCliente method should have a different indentifier, maybe setNomeFromKeyboard.
Your Depositar method has two problems.1: It should be called depositar. Not D but d.2: You are adding a double to an int. This cannot be compiled as it stands.I would change that method to thisYour Saca method has similar problems. You should also consider this sort of problem: The Conta object has a saldo of 1000. You try this method call: miConta.saca(2000); You need to provide if blocks for whether the quantitade is > 0 or > saldo. I suggest, maybe, you return quantitade if it is in the right range; if it is <= 0 or > saldo, then return 0. You can use it like this.I hope this give you some idea how to proceed. Please ask again if you have more problems.
|
 |
 |
|
|
subject: Comunication between classes
|
|
|