Banking Create And Closing Account

How to create and close? Help me with it. Thanks

Page 1 of 1

2 Replies - 2841 Views - Last Post: 27 July 2010 - 07:40 PM Rate Topic: -----

#1 kaikai  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-July 10

Banking Create And Closing Account

Posted 27 July 2010 - 07:15 PM

import java.util.Scanner;
   import java.text.*; 

    public class S10091234_AssignmentTemplate
    
   {
       public static void main(String[] args);
         
      {
         Scanner scn = new Scanner(System.in);
         int[]    accNumber  = new int[20];	 	  	// array to store account numbers
         String[] accName    = new String[20]; 	 	// array to store account names
         double[] accBalance = new double[20] ; 	// array to store account balances
         int count;											// stores the number of bank accounts
         int choice=1;
      
      // initialize the arrays with some accounts
         count = initAccounts(accNumber, accName, accBalance);
      	
         
         
         while(choice !=5)
         {
            displayMenu();
            choice=scn.nextInt();
            if(choice==1)
            {
               displayAllAccounts(accNumber, accName, accBalance, count);
            }
            else  
               if(choice==2)
               {
                  displayAllAccounts(accNumber, accName, accBalance, count);
                  depositMoney(accBalance, count);
               }
               else
                  if(choice==3)
                  {	
                     displayAllAccounts(accNumber, accName, accBalance, count);
                     withdrawMoney(accBalance, count);
                  }
                  else
                     if(choice==4)
                     {  
                        double tempVar = findHighestBalance(accNumber, accName, accBalance);
                     
                        for (int x = 0; x < accBalance.length; x++)
                           if (tempVar==accBalance[x])
                           {
                              System.out.println("Highest Balance Account :");
                              System.out.println("Account Number\tAccount Name\tBalance[$]");
                              System.out.println(accNumber[x]+"\t"+accName[x]+"\t"+accBalance[x]);
                           }
                     }
                     else
                        if(choice==5)
                           System.out.println("Exit");
                        else
                           System.out.println("Error! Please Key In The Correct Choice.");
         }
      	
      
      
      }
   
   // method to initialize some bank accounts
       public static int initAccounts(int[] accNumber, String[] accName, double[] accBalance)
      {
         int count = 0;
      
         accNumber[0] = 111111;
         accName[0] = "Kevin Tan";
         accBalance[0] = 10000.00;
         count++;
      
         accNumber[1] = 222222;
         accName[1] = "Janice Ng";
         accBalance[1] = 20000.00;
         count++;
      
         accNumber[2] = 333333;
         accName[2] = "Wendy Sng";
         accBalance[2] = 30000.00;
         count++;
      
         accNumber[3] = 444444;
         accName[3] = "Brian Ong";
         accBalance[3] = 40000.00;
         count++;
      
         accNumber[4] = 555555;
         accName[4] = "Terry Lee";
         accBalance[4] = 50000.00;
         count++;
      
         return count;
      }
       public static void displayMenu()
      {
      	// display main menu
         System.out.println("Main Menu");
         System.out.println("[1] Display All Accounts.");
         System.out.println("[2] Deposit Money.");
         System.out.println("[3] Withdraw Money.");
         System.out.println("[4] Locate The Highest Balance Of The Accounts.");
         System.out.println("[5] Exit.");
         System.out.print("Enter Your Option: ");
      }
   
      // Method to display account
       public static void displayAllAccounts(int[] accNumber, String[] accName,double[] accBalance, int count)
      {
         System.out.println("Serial \tAccount\tName\t\tBalance");
      	
         for (int n=0 ;n<count; n++)
            System.out.println((n+1)+ "\t" + accNumber[n] + "\t" +accName[n] + "\t" + accBalance[n]);
      }
      
   	// Method To Deposit Money
       public static void depositMoney(double[] accBalance, int count)
      {
         Scanner scn = new Scanner(System.in);
         System.out.print("Select Account: ");
         int y = scn.nextInt();
         if (y > count)
         {
            System.out.println("Error! Please Key In The Correct Choice.");
         }
         else
         {
            System.out.print("Key In The Amount To Deposit: ");
            double a = scn.nextDouble();
         	
            if (a < 0)
            {
               System.out.println("Error! Please Key In The Correct Amount.");
            }
            else
            {
               accBalance[y-1]+=a;
               System.out.println("Money Is Deposited Successfully.");
            }
         }
      }
   
   // Method To Withdraw Money
       public static void withdrawMoney(double[] accBalance, int count)
      {
         Scanner scn = new Scanner(System.in);
         System.out.print("Select Account: "); 
         int y = scn.nextInt();
         if (y > count)
         {
            System.out.println("Error! Please Key In The Correct Choice.");
         }
         else
         {
            System.out.print("Key In The Amount To Withdraw: ");
            double a = scn.nextDouble();
         
            if (a < 0 || a > accBalance[y-1])
            {
               System.out.println("Error! Please Key In The Correct Amount.");
            }
            else
            {
               accBalance[y-1]-=a;
               System.out.println("Money Is Withdrew Successfully.");
            }
         }
      }
   
   	// Method To Find The Highest Balance Of All
       public static double findHighestBalance(int[] accNumber, String[] accName, double[] accBalance)
      {
         double highestBalance;
         highestBalance = accBalance[0];
         for (int b=0; b<accBalance.length; b++)
         {
            if (accBalance[b] > highestBalance)
               highestBalance = accBalance[b];
         }
         return highestBalance;
      }
   }




HOW TO CREATE AND CLOSE ACCOUNT? :D HELP ME WITH IT THANKS

This post has been edited by no2pencil: 27 July 2010 - 07:17 PM
Reason for edit:: Added code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Banking Create And Closing Account

#2 bcranger  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

Re: Banking Create And Closing Account

Posted 27 July 2010 - 07:22 PM

You will want to use Object-Oriented design. An Account class is neccessary to hold all your information for the accounts, much easier compared to your 3 arrays holding the data. To create an account, instantiate an object of class Account, or a subclass such as SavingsAccount, and add it to your array, arraylist, etc. To delete it, simply use a loop to search through the array and if a matching account is found, delete it or null it.
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8329
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Banking Create And Closing Account

Posted 27 July 2010 - 07:40 PM

Have a look a macosxnerd101 tutorial on how to go from parallel arrays to an array of a single class
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1