How to call a variable from other class

Reply

Join Date: Oct 2008
Posts: 37
Reputation: l_03 has a little shameless behaviour in the past 
Solved Threads: 0
l_03 l_03 is offline Offline
Light Poster

How to call a variable from other class

 
0
  #1
Nov 16th, 2008
guyzzz,,,help,,i dont know how to call a variable from other class,,could you help me,,huhuhuh,,,i really need your help...

i have a class,,
this is just a summary...

public class BankAccount{
int accountNumber[] = {1234, 2345};

public class ATM{

BankAccount bank = BankAccount();
String accountNum;
int accountNum2;

accountNum = JOptionPane.showInputDialog("Please enter your account number: ");
accountNum2 = Integer.parseInt(accountNum);

if(accountNum==bank.accountNumber[0]){
JOptionPane.showMessageDialog(null, "Card Accepted.");

}else{
JOptionPane.showMessageDialog(null,"Card is not valid.");

there is no error but when i run it,,,i dont know,,but the eclipse dont read the bank.accountNumber[0].. and prints the ("Card is not valid.")..
i dont know what to do...

help........
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 249
Reputation: Antenka has a spectacular aura about Antenka has a spectacular aura about Antenka has a spectacular aura about 
Solved Threads: 65
Antenka's Avatar
Antenka Antenka is offline Offline
Posting Whiz in Training

Re: How to call a variable from other class

 
0
  #2
Nov 16th, 2008
You are compering 2 different types String accountNum and int accountNumber[0]. This is interesting, that you run it without troubles
As I understand, it must be like that:
f(accountNum2==bank.accountNumber[0])
So what if you can see the darkest side of me?
No one would ever change this animal I have become
Help me believe it's not the real me
Somebody help me tame this animal
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 37
Reputation: l_03 has a little shameless behaviour in the past 
Solved Threads: 0
l_03 l_03 is offline Offline
Light Poster

Re: How to call a variable from other class

 
0
  #3
Nov 16th, 2008
Originally Posted by Antenka View Post
You are compering 2 different types String accountNum and int accountNumber[0]. This is interesting, that you run it without troubles
As I understand, it must be like that:
f(accountNum2==bank.accountNumber[0])

oh i type it wronly,,thanks for the correction,,,,

yeah in my code it was like that

if (accountNum2==bank.accountNumber[0]){
//code above..with the thread i've started.....

...help,,,
Last edited by l_03; Nov 16th, 2008 at 11:05 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 9
Reputation: Drosty is an unknown quantity at this point 
Solved Threads: 0
Drosty's Avatar
Drosty Drosty is offline Offline
Newbie Poster

Re: How to call a variable from other class

 
0
  #4
Nov 17th, 2008
Originally Posted by l_03 View Post
guyzzz,,,help,,i dont know how to call a variable from other class,,could you help me,,huhuhuh,,,i really need your help...

i have a class,,
this is just a summary...

public class BankAccount{
int accountNumber[] = {1234, 2345};

public class ATM{

BankAccount bank = BankAccount();
String accountNum;
int accountNum2;

accountNum = JOptionPane.showInputDialog("Please enter your account number: ");
accountNum2 = Integer.parseInt(accountNum);

if(accountNum==bank.accountNumber[0]){
JOptionPane.showMessageDialog(null, "Card Accepted.");

}else{
JOptionPane.showMessageDialog(null,"Card is not valid.");

there is no error but when i run it,,,i dont know,,but the eclipse dont read the bank.accountNumber[0].. and prints the ("Card is not valid.")..
i dont know what to do...

help........
In your BankAccount class create a getter that will return the bank account information.

  1.  
  2. public int[] getBankAccountInformation(){
  3. return accountNumber;
  4. }

and then when it is returned, see if what the user inputted matches the data in the array.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 37
Reputation: l_03 has a little shameless behaviour in the past 
Solved Threads: 0
l_03 l_03 is offline Offline
Light Poster

Re: How to call a variable from other class

 
0
  #5
Nov 17th, 2008
Originally Posted by Drosty View Post
In your BankAccount class create a getter that will return the bank account information.

  1.  
  2. public int[] getBankAccountInformation(){
  3. return accountNumber;
  4. }

and then when it is returned, see if what the user inputted matches the data in the array.

is it really works???ok i will try this out,,,thank you for the help...thank youuuuuuuu so much guyzzz...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC