Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic Java Help Required....

Status
Not open for further replies.

Smith121

Programmer
Jan 15, 2005
2
GB
I'm designing a very basic Object-Oriented program in netbeans using java, but I'm stuck, I just wonder if anyone could help me....?

Created Accounts:

ACC NUM NAME BALANCE
246246 James Taylor 100
123123 Chris Smith 0

I created two new accounts using the values above and returned them to the class constructor but I’m stuck on how to retrieve the information back.

For example:
Acc Number: 123123
*** Welcome ***
Chris
Your balance is: 0

Or/and

Acc Number: 101010
*** Sorry no account found ****

Also: -

After that I wish to allow the use to enter the amount they wish to withdraw or deposit for that particular account.

Is this possible?

Any help will be very much appreciated!
Thanks
Chris
 
Code:
class Account
      {
       String accNum;
       String nameAcc;
       int balanceAcc;
       public Account(String accNum, String name, int balance)
              {
               this.accNum = accNum;
               this.nameAcc = name;
               this.balanceAcc = balance;
              }
       public int getBalance()
              {
               return balanceAcc;
              }

       public void setBalance(int temp)
              {
               balanceAcc = temp;
              }
       public String getNameAcc()
              {
               return nameAcc;
              }
       public void setNameAcc(String temp)
              {
               nameAcc = temp;
              }

      }
class acctest
      {
       public boolean searchAccByName(Account tempArray[],String temp)
              {
               boolean isFound = false;
               for (int i=0; i<tempArray.length;i++)
                   {
                    if (tempArray[i] == null)
                       continue;
                    if ( (tempArray[i].getNameAcc()).equals(temp) )
                       {
                        isFound = true;
                        System.out.println("Your balance is: "+tempArray[i].getBalance());
                       }
                   }    
               if (isFound)
                   return true;
               else
                   return false;
              }
       public static void main(String args[])
              {
               Account accountArray[] = new Account[100]; // there can be maximum 100 accounts
               accountArray[0] = new Account("246246","James Taylor",100);
               accountArray[1] = new Account("123123","Chris Smith",0);   
               acctest acctestObj = new acctest();
               System.out.println("Chris Smith");
               if (!acctestObj.searchAccByName(accountArray,"Chris Smith") )
                   System.out.println("No such Account");
              }
      }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top