Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Needs help in my program of a bank account!

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Needs help in my program of a bank account!

    I need to do an assignment with the question requirement as follow.
    -The system to maintain a list up to 20 accounts. Each account has a unique account number and account balance.
    -Need to perform the following tasks repeatedly until he quits.(add account, search account and display account).
    Your program should include the following:
    -Two arrays, one to store the account number and the other to store the account balance.
    -The method displayMenu() to display the following menu:
    Menu
    1. Add an account
    2. Search an account with the given account number
    3. Display accounts below the given balance
    0. Exit
    - The method addAccount() to add an account to the system. This method should receive
    as the parameters the two arrays mentioned above and an integer number that keeps track
    of the number of accounts so far. It prompts and reads the account number and account
    balance from the user and adds it to the system. The method should return the total
    number of accounts. You are required to ensure that the number of accounts in the system
    is less than 20 before prompting for input. You are also required to ensure that the
    account number is unique (note: you may use the search() method written below for
    the validation).
    - The method search() to search for an account with the account number entered by the
    user. The method should return the index of the account in the array if it is found, or -1 if
    it is not found.
    - The method displayAccounts() to display all the accounts that has the balance
    below the amount entered by the user.
    - The main() method that calls the desired method to perform the task according to the
    user's selection. You are required to use switch statement here.


    This is my code until so far. i am stuck till the add account.
    Really appreciate if any pro out there can help me with this.

    import java.util.*;

    public class Qn3{
    public static void main(String[]args){
    Scanner scn = new Scanner(System.in);
    int [] accNum = new int[20];
    double [] accBal = new double[20];
    new Qn3();
    switch ( scn.nextInt() ) {
    case 1:
    System.out.println ( "You picked option 1" );
    addAccount(accNum);
    case 2:
    System.out.println ( "You picked option 2" );
    break;
    case 3:
    System.out.println ( "You picked option 3" );
    break;
    default:
    System.err.println ( "Unrecognized option" );
    break;
    }
    }
    public void displayMenu(){
    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("0. Exit");
    }
    public static void addAccount(int[] accNum, double [] accBal){
    Scanner scn = new Scanner(System.in);

    for (int n=0; n<accNum.length; n++)
    {
    if(accNum[n] == 0){
    System.out.print("Enter account Number " + (n+1) + ": ");
    accNum[n] = scn.nextInt();
    }
    }
    }
    public Qn3(){
    displayMenu();
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,661
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: Needs help in my program of a bank account!

    Please explain what your problem is and ask some specific questions about what you want to do.


    Please Edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Aug 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Needs help in my program of a bank account!

    import java.util.*;
     
    public class Qn3{
    public static void main(String[]args){
    Scanner scn = new Scanner(System.in);
    int [] accNum = new int[20];
    double [] accBal = new double[20];
    new Qn3();
    switch ( scn.nextInt() ) {
    case 1:
    System.out.println ( "You picked option 1" );
    addAccount(accNum);
    case 2:
    System.out.println ( "You picked option 2" );
    break;
    case 3:
    System.out.println ( "You picked option 3" );
    break;
    default:
    System.err.println ( "Unrecognized option" );
    break;
    }
    }
    public void displayMenu(){
    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("0. Exit");
    }
    public static void addAccount(int[] accNum, double [] accBal){ 
    Scanner scn = new Scanner(System.in);
     
    for (int n=0; n<accNum.length; n++) 
    { 
    if(accNum[n] == 0){
    System.out.print("Enter account Number " + (n+1) + ": "); 
    accNum[n] = scn.nextInt();
    }
    } 
    } 
    public Qn3(){
    displayMenu();
    }
    }

    Hi Norm,
    Thanks for replying.
    Im stuck at add account. I have no idea how to start this question.
    So was wondering if any one can at least give me a headstart or clue on how to start this program.
    Hope you can help me with it.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,661
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: Needs help in my program of a bank account!

    What should be done when an account is added?
    What data does the program need to open a new account?
    Where will the program store the data about the new accounts so it can access them when it needs to?

    The posted code needs to be formatted by adding indentations of 3-4 spaces to statements that are at different nesting levels of logic. The posted code all starts in the first column which makes it hard to see the logic.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Simple Bank Account Program
    By ZaneCruise in forum Threads
    Replies: 1
    Last Post: April 4th, 2012, 09:35 PM
  2. Bank Account Program re-post
    By kfdhihi in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 8th, 2011, 09:29 AM
  3. help with my bank account program
    By captain_turkiye in forum Object Oriented Programming
    Replies: 3
    Last Post: October 14th, 2011, 10:33 AM
  4. Bank Account Program.
    By Punky0214 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: November 17th, 2010, 09:42 PM
  5. How to delete records from a Random-Access File?
    By keith in forum File I/O & Other I/O Streams
    Replies: 10
    Last Post: March 31st, 2009, 11:40 AM