Results 1 to 5 of 5
  1. #1
    jackandjill is offline Member
    Join Date
    Aug 2012
    Posts
    5
    Rep Power
    0

    Lightbulb A simple bank program as homework

    I had the follow question as homework last sem but failed to do it and now tried and got so far can anyone help with the rest as i am not able to figure out.. and i have clearly stated out the details, please see the attachments


    A simple bank program as homework-capture.jpg

    I have done some what you can say the ground work like the addaccount() method
    and the whole skeleton structure

    MORE DETAILED EXPLANATION

    AddAccount() method
    -- INPUTS--
    AccountNumber, this will have to be a string array and should be able to store no more than 20.
    This has to be in this format.
    9 alphanum characters no less no more, first and last char always Uppercase even though the user inputs it as small case it has to be store in the array as Upper Case. The rest of the characters have to be numbers ONLY.

    AccountBalance, this will have to be an array not sure what kind of array type best suitable for money.
    This has to be in this format
    any number is fine infinte to as low as 0.00. But has to have 2decimal places ONLY. MOST IMPORTANTLY the number has to match the Accountnumber array index so it has to be linked to that.
    If no value is given by default it has to take 0.00 automatically.


    --PROCESS--
    After the inputs are taken there is a validation process. In the validation process
    -> Check the account number is 9char
    -> Check the first and last digits of the AccountNumber are Alphabets and the middle characters are numerics ONLY
    ->If the AccountNumber does not meet the specified requirements prompt again to retype or press 0 to exit to main method.
    ->If the AccountNumber IS valid Search() method will search if there is an existing AccountNumber in the array and prompts the user about this.
    ->If the AccountNumber doesnot exist then the AccountNumber IS valid? proceed ahead with adding the AccountNumber to the array, with first and last char converted to UPPERCASE if needed.
    -> After the AccountNumber is verified and added to the array, prompt for the AccountBalance.
    ->If AccountBalance is not entered and then default value is 0.00, IF entered then the value has to be 0.00 format ONLY, if needed ROUND_DOWN
    MOST IMPORTANTLY BOTH THE AccountNumber and AccountBalance ARRAYS INDEXES HAVE TO BE ALIGNED.





    Search() method
    --INPUTS--
    AccountNumber array from the AddAccount() method
    User input, AccountNumber

    --PROCESS--
    Check if AccountNumber has 9digits and last and first char are alpha ONLY and the rest are numbers ONLY, and convert the last and first to Upper case if needed and then
    Search for the account in the AccountNumber array
    IF exists, returns the index of the AccountNumber with AccountBalance
    ELSE return -1


    displayAccounts() method
    --INPUTS--
    AccountNumber array and AccountBalance array from the AddAccount() method
    User input , AccountBalance

    --PROCESS--
    Check if AccountBalance is in the required format of 0.00 if not convert it, ROUND_DOWN
    Search for the accounts that have balance below the entered amount
    If exists then display all the AccountNumbers and the AccountBalance, one per line
    ELSE println no accounts found below that AccountBalance




    MY CODE SO FAR
    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package qn3;
    
    import java.math.BigDecimal;
    import java.math.RoundingMode;
    import java.text.DecimalFormat;
    import java.util.Arrays;
    import java.util.Scanner;
    
    /**
     *
     * @author jackandjill
     */
    public class Qn3
    {
    
        /**
         * @param args the command line arguments
         */
        
       public static void main(String[] args)
       {
           displayMenu();
    
       }
    
        public static void displayMenu()
        {
            
            int option,accno;
            double accbal;
            Scanner sc = new Scanner(System.in);
            //={"chanan","tapan","Amar","santosh","deepak"};
           
            System.out.println("---//---Menu---//---");
            System.out.println("1. Add an account");
            System.out.println("2.Search an account with the given account number");
            System.out.println("3.Display accounts below the given balance");
            System.out.println("4.Exit");
            System.out.print("Please Enter Your Choice: ");
            
            option = sc.nextInt();
     
            switch(option)
            {
                
                case 1:
                        System.out.println("You have choosen to add account");
                        addAccount();
                        break;
                case 2:
                        System.out.println("You have choosen to search for an account");
                        search();
                        break;
                case 3:
                        System.out.println("You have choosen to search for accounts below specified balance");
                        break;
                case 0:
                        System.out.println("You have choosen to exit");
                        break;
                default:
                         System.out.println("Please choose the choice an option appropriately as displayed");
                                                
            }
           
            
        }
    
        public static String[] addAccount()
        {
            //String accno;
            int i=0;
            String accno, input;
            BigDecimal accbala;
            DecimalFormat df = new DecimalFormat("0.00");
            BigDecimal[] accbal= new BigDecimal[20];
            Scanner sc = new Scanner(System.in);
            String[] accnums = new String[20];
            
            System.out.print("Enter the account number:");
            accno = sc.nextLine();        
            if(accno.length() != 9)
            {
                System.out.println("Wrong NRIC");
            }
            else
            {
                System.out.print("Enter account balance");
                accbala = sc.nextBigDecimal(); 
                while (sc.hasNextBigDecimal()) 
                {
                      System.out.println(sc.nextBigDecimal().setScale(2, RoundingMode.HALF_UP));
                }
    
              int j;
              for (j = 0; j < accnums.length; j++)
              if (accnums[j] == null) break;
              if (j==accnums.length)  
              {
                    System.out.print("Account storage limit has reached.");
              } 
              else
              { 
                  accnums[j]=accno;               
              }
    
            }
            
            input= accnums[0];
           System.out.println("The value:"+input+"witha a balance of "+accbal);
           return accnums;
        }
    
        
        public static void search()
        {
            String[] acnumArray;
            String accnuminput;                
            acnumArray = addAccount();
            
            Scanner sc = new Scanner(System.in);
            
            System.out.print("Enter account number to search");
           accnuminput = sc.nextLine();
            
           if(Arrays.asList(acnumArray).contains(accnuminput))
           {
               System.out.println("The value is contained");
           }
           else
           {
               System.out.println("The value is not contained");
           }
            
        }
        
         public static void displayaccounts(String[] acnumArray,BigDecimal[] acbalArray,String balinput)
        {
            
           if(Arrays.asList(acnumArray).contains(balinput))
           {
               System.out.println("The value is contained");
           }
           else
           {
               System.out.println("The value is not contained");
           }
            
        }
        
        
    }

  2. #2
    Zyril is offline Senior Member
    Join Date
    Oct 2011
    Location
    Sweden
    Posts
    124
    Rep Power
    0

    Default Re: A simple bank program as homework

    Hi jackandjill!

    Java is an object oriented programming language where you create classes (blueprints) of which you then can create objects. These objects can then later on be used or referenced to within the program.

    Wouldn't it be nice to create a class called Account, which is a blueprint for account objects, from which you then create all the account objects you need? These objects can then be stored in an ArrayList where they are easily accessed.

    You seem to be able to code what you want to code, you just have to know how to structure it.
    If I were you, I would do exactly as I suggested above. Create a class for the Account, with all the necessary information about an account. When an account has been created, store it in an ArrayList<Account>.

    Hope this helps!
    Good luck,
    Z!

  3. #3
    jackandjill is offline Member
    Join Date
    Aug 2012
    Posts
    5
    Rep Power
    0

    Default Re: A simple bank program as homework

    Quote Originally Posted by Zyril View Post
    Hi jackandjill!

    Java is an object oriented programming language where you create classes (blueprints) of which you then can create objects. These objects can then later on be used or referenced to within the program.

    Wouldn't it be nice to create a class called Account, which is a blueprint for account objects, from which you then create all the account objects you need? These objects can then be stored in an ArrayList where they are easily accessed.

    You seem to be able to code what you want to code, you just have to know how to structure it.
    If I were you, I would do exactly as I suggested above. Create a class for the Account, with all the necessary information about an account. When an account has been created, store it in an ArrayList<Account>.

    Hope this helps!
    Good luck,
    Z!
    yes that is correct but i want to know the exact syntax and some of the logic i am not able to implement.. tks for the advice though..

  4. #4
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    2

    Default Re: A simple bank program as homework

    Quote Originally Posted by jackandjill View Post
    yes that is correct but i want to know the exact syntax and some of the logic i am not able to implement.. tks for the advice though..
    You aren't going to receive a completed assignment on this forum. It's best if you ask a specific question. What don't you understand how to do?
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  5. #5
    Zyril is offline Senior Member
    Join Date
    Oct 2011
    Location
    Sweden
    Posts
    124
    Rep Power
    0

    Default Re: A simple bank program as homework

    Looking at your code, I get the impression that you know what it does and how to use the different objects and classes, only that you are doing it the wrong way.

    Start by just doing as I suggested, write a new class simply just for the Account's. You can re-use a lot of the code that you've already written.

Similar Threads

  1. program ,deposit of an amount of money in a bank
    By aou in forum Advanced Java
    Replies: 1
    Last Post: 08-03-2012, 09:41 PM
  2. Simple Homework applet problems
    By ADustedEwok in forum Java Applets
    Replies: 1
    Last Post: 12-08-2011, 10:11 PM
  3. Simple Bank Account Program - Completely Confused
    By Interista in forum New To Java
    Replies: 4
    Last Post: 11-02-2011, 02:12 AM
  4. Bank program difficulties
    By LifeElixer in forum New To Java
    Replies: 8
    Last Post: 10-21-2011, 04:42 AM
  5. Replies: 4
    Last Post: 11-02-2009, 03:41 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •