Deposit account


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Deposit account

Hybrid View

  1. #1
    Join Date
    Dec 2004
    Posts
    46

    Deposit account

    Hi,

    I have wrote a program that (nearly) performs in the following way:
    • When the program starts two bank accounts are created, using names and numbers written into the code;
    • The user is then asked to enter an account number, followed by an amount to deposit in that account;
    • The balance of the appropriate account is then updated accordingly, or if an incorrect account number was entered a message to this effect is displayed;
    • The user is then asked if he or she wants to make more deposits;
    • If the user answers ‘yes’, the process continues;
    • If the user answers ‘no’, the both account details (account number, account name and balance) are displayed.

    It compiles fine, I am just not sure how to change it so when you enter an account number (has to be 283748 or 289736) then if it is valid it shows the current balance then goes through all the options I have already wrote but with that account not the other account. There may be other points above that may not be included in the code.

    Here is the code:



    Code:
    public class BankAccount2
    {
        public static void main (String[]args)
    {
        double num; 
        char choice;
    
        BankAccount account1 = new BankAccount ("283748", "Angelo Di Livio"); // account number and name
        BankAccount account2 = new BankAccount ("289736", "Donald Duck");
          
          account1.deposit(1000);// Angelo's current balance
          account2.deposit(2000);// Donald's current balance
       
       System.out.println("Enter Account Number");
       ????????????????????????????
          
          
          do
          {
          System.out.println("       BANK ACCOUNT");
          System.out.println("****************************\n\n");
          System.out.println("Enter The Amount You Wish To Deposit: ");   
          num = EasyIn.getDouble();
          account1.deposit(num);
          System.out.println("Your Balance Is Now: "  +  account1.getBalance());
          System.out.println ("Account Name: "  +  account1.getAccountName());
          System.out.println ("Account Number: "  +  account1.getAccountNumber());
           
          System.out.print ("Do you want make more deposits(y/n): ");
          choice = EasyIn.getChar();
          }while (choice == 'y' || choice == 'Y');
          System.out.println(" ");
          System.out.println("       FINAL STATEMENT"); // if user enters no then final statement is shown
          System.out.println("****************************\n\n");
          System.out.println("Your Overall Balance Is: "  +  account1.getBalance());
          System.out.println ("Account Name: "  +  account1.getAccountName());
          System.out.println ("Account Number: "  +  account1.getAccountNumber());
    
    }
    }
    Any feedback would be very helpful.
    Thanks

  2. #2
    Join Date
    Dec 2004
    Location
    france
    Posts
    35
    Well the thing is
    when you write programs like this
    they may compil fine
    and even run fine
    but it's not a good programming habit

    you really need to creat the Object bankAccount first with it's fields and methods including deposit and withdrawal
    and any other things you feel like a bank account should have
    then you'll have main method right a bottom to instantied that class then
    call on different method
    good luke!
    Compil and run!

  3. #3
    Join Date
    Dec 2004
    Posts
    46
    Like a said previously this is just a deposit account and im following through steps from a book.

    Anyway thanks for your advice.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center