Results 1 to 4 of 4
  1. #1
    bnto_kmls is offline Member
    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0

    Default Help bank account assignment

    Hey guys,

    Need help with a bank account homework. Its not showing me the amount I deposit when I create the account for option 1 and 2 nor when I deposit it with option 3. Also, its not letting me show the interest rate for option 5 and 9. Have been trying to figure it out and so far, no success.

    Any help would be appreciated

    Thanks!

    Here is the bank menu

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package bankmenu;
    
    import java.util.Scanner;
    
    /**
     * This program reads the selection of customer account.
     * @author Benito Kmls
     * @version 11/03/13
     */
    public class BankMenu {
    
        /**
         * This program reads the selection from customer account.
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            
            //Declare variables
            int nSelection = 0;                                     //Menu selection
            int nNextAccountNumber = 0;                             //Next account number
            double dBeginBal = 0.0;                                 //Customer beginning balance
            double dIntRate = 0.0;                                  //Customer beginning interest rate
            BankAccount bankAccountUser = null;                     //Create data storage for accounts
            double dDepAmt = 0.0;                                   //Customer deposit certain amount
            double dWDrawAmt = 0.0;                                 //Customer withdraw certain amount
            double dIntEarned = 0.0;                                //Customers monthly interest earned
            double dCustAcctBal = 0.0;                              //Customers account balance
            double dNewIntRate = 0.0;                               //Customers new interest rate
            
            //Prompt product menu
            System.out.println("ACCOUNT PROCESSING MENU");
            
            System.out.println("1. Create new account - empty account");
            
            System.out.println("2. Create new account - information available");
            
            System.out.println("3. Make deposit");
            
            System.out.println("4. Make withdrawal");
            
            System.out.println("5. Calculate monthly interest");
            
            System.out.println("6. View account balance");
            
            System.out.println("7. Next available account number");
            
            System.out.println("8. Update monthly interest rate");
            
            System.out.println("9. Print account information");
            
            System.out.println("10. Exit");                              
                                
            //Start while loop
            while (nSelection != 10){                                   
                
                //Prompt selection
                System.out.print("Please enter you preferred option: ");
                
                //Read integer
                nSelection = input.nextInt();
                
                //Customer creates new account
                bankAccountUser = new BankAccount();
                
                if (nSelection == 1){                               
                                                   
                     //Prints customers new account
                     System.out.println("Account # " + bankAccountUser.getAccountNumber() + " successfully created. ");                              
                    
                }//end selection 1 if                       
                         
                else if (nSelection == 2){
                                               
                     //Prompt customer for starting balance
                     System.out.print("Please enter your starting balance: ");
                     
                     //Read customers balance
                     dBeginBal = input.nextDouble();
                     
                     //Prompt customer for monthly interest rate
                     System.out.print("Please enter the monthly interest rate: ");
                     
                     //Read customers interest rate
                     dIntRate = input.nextDouble();
                     
                     //Customer create new account
                     bankAccountUser = new BankAccount(dBeginBal, dIntRate);
                     
                     //Print customer new account
                     System.out.println("Account # " + bankAccountUser.getAccountNumber() + " successfully created. ");   
                    
                }//end selection 2 if
                
                else if (nSelection == 3){
                    
                     //Prompt customer for deposit amount
                     System.out.print("Please enter your deposit amount: ");
                     
                     //Read deposit amount
                     dDepAmt = input.nextDouble();
                     
                     //Creates new account
                     bankAccountUser.makeDeposit(dDepAmt);
                    
                }//end selection 3 if
                
                else if (nSelection == 4){
                    
                    //Prompt customer for withdrawl amount
                     System.out.print("Please enter the withdrawal amount: ");
                     
                     //Read withdrawal amount
                     dWDrawAmt = input.nextDouble();
                     
                     //Analyze function for makeWithdrawal method
                     boolean makeWithdrawal = bankAccountUser.makeWithdrawal(dWDrawAmt);
                     
                     //if function for message
                     if(makeWithdrawal == true){
                         
                         System.out.println("Withdrawal successful.");
                     
                     }//end if function
                     
                     //else funcion if false
                     else {
                         
                         System.out.println("Insufficient funds. Withdrawal not made.");    
                     
                     }//end else false print insufficient funds  
                    
                }//end selection 4 if
                
                else if (nSelection == 5){
                    
                     //Call inter earned per month
                     dIntEarned = bankAccountUser.monthlyInterest();
                     
                     //Print interest rate earned
                     System.out.println("Monthly interest earned: $" + dIntEarned);    
                    
                }//end selection 5 if
                
                else if (nSelection == 6){
                    
                     //Call account balance
                     dCustAcctBal = bankAccountUser.getBalance();
                     
                     //Print cust. account balance
                     System.out.println("Your account balance: $" + dCustAcctBal);   
                    
                }//end selection 6 if
                
                else if (nSelection == 7){
                    
                     //Call account balance
                     nNextAccountNumber = bankAccountUser.getNextAccountNumber();
                     
                     //Print next account number
                     System.out.println("Next available account number: " + nNextAccountNumber);
                    
                }//end selection 7 if
                
                else if (nSelection == 8){
                    
                    //Prompt customer new monthly interest rate
                     System.out.print("What is the new monthly interest rate? ");
                     
                     //Read customer new int rate input 
                     dNewIntRate = input.nextDouble();
                     
                     //Set new int rate
                     bankAccountUser.setMonthlyInterestRate(dNewIntRate);
                    
                }//end selection 8 if
                
                else if (nSelection == 9){
                    
                     //Call BankAccount class for account info
                     bankAccountUser.printBankInfo();
                    
                }//end selection 9 if
                
                //Else if function to exit program.                                      
                 if (nSelection == 10){
                     
                     //Print exit
                     System.out.println("Exiting Program.");
                 
                 }//end else if function for selection 10
                
            }//end while statement
            
        }
    }
    This is the bank account class:

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package bankmenu;
    
    /**
     *
     * @author Benito Kmls
     */
    public class BankAccount{
        
        /** Stores the account numbers */
        private int nAccountNumber = 12345;
        
        /** Stores the next account numbers */
        private int nNextAccountNumber = 0;
    
        /** Stores the balance */
        private double dBalance = 0.0;
        
        /** Stores the balance */
        private double dMonthlyInterestRate = 0.0;    
        
        /** Stores withdrawal */
        private double dWithdraw = 0.0;
        
        /** Stores Int per month */
        private double dIntPerMth = 0.0;      
       
        
        /**
         * Default constructor
         */
        public BankAccount(){
            
            //create a new account number for customer
           nNextAccountNumber = nAccountNumber + 1;
            
        }//end default constructor
        
        /**
         * Constructor receiving balance and interest rates
         * @param dStartBalance
         * @param dIntRate 
         */
        public BankAccount(double dStartBalance, double dIntRate){
            
            //Set new balance
            dBalance = dStartBalance;
            
            //Set new monthly interest rate
            dMonthlyInterestRate = dIntRate;
            
        }//end overloaded constructor
        
        /**
         * Accessor for nAccountNumber
         * @return AccountNumber
         */
        public int getAccountNumber(){       
            
            return nAccountNumber;
            
        }//end method getAccountNumber - accessor 
        
        /**
         * Accessor for dBalance
         * @return Balance
         */
        public double getBalance(){
            
            return dBalance;
            
        }//end method getBalance - accessor
        
        /**
         * Accessor for dMontlyInterestRate
         * @return InterestRate
         */
        public double getMonthlyInterestRate(){
            
            return dMonthlyInterestRate;
            
        }//end method getMonthlyInterestRate - accessor
        
        /**
         * Mutator for dMonthlyInterestRate
         * @param dRate 
         */
        public void setMonthlyInterestRate(double dRate){
            
            //Set new value of width
            dMonthlyInterestRate = dRate;
            
        } //end method setMonthlyInterestRate - mutator
        
        /**
         * Accessor for nNextAccountNumber
         * @return NextAccountNumber
         */
        public int getNextAccountNumber(){        
            
            return nNextAccountNumber;
                    
        }//end method getNextAccountNumber - accessor
        
        /**
         * Mutator for statements
         */
        public void printBankInfo(){
            
            System.out.println("Account number: " + nAccountNumber);
            
            System.out.println("Account balance: $" + dBalance);
            
            System.out.println("Monthly interest: $" + dMonthlyInterestRate);
            
        }
        
        /**
         * Mutator for dDepositAmt
         * @param dDepositAmt 
         */
        public void makeDeposit(double dDepositAmt){
            
            //Calculates balance and deposit using the add assignment operator
            dBalance += dDepositAmt;
            
        }//end method make deposit
        
        /**
         * Boolean
         * @param dWithdrawalAmt
         * @return true
         */
        public boolean makeWithdrawal(double dWithdrawalAmt){    
             dWithdraw = dWithdrawalAmt;
            
             // if function to make sure customers have enough funds in account to cover withdrawal using the subtract assignment operator
            if(dWithdraw > dBalance){
                
                dBalance -= dWithdraw;
            
                return true;
            
            }//end if Function for withdrawal boolean
            
            //else function to return a no go on withdrawal
            else 
                           
                return false;
            
        }//end method makeWithdrawal
        
        /**
         * Accessor for MonthlyInterestRate
         * @return dIntPerMth 
         */
        public double monthlyInterest(){
            
            //dInterestPerMonth equals Interest earned per month
            dIntPerMth = dMonthlyInterestRate * dBalance;
    
            return dIntPerMth;
    
        }//end method monthlyInterest
        
        }//end method

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,520
    Blog Entries
    7
    Rep Power
    20

    Default Re: Help bank account assignment

    You have a nice printBankInfo() method in your BankAccount class; call it after you have made a deposit etc. and see if the changes make it in your BankAccount object.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    bnto_kmls is offline Member
    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0

    Default Re: Help bank account assignment

    Thanks for the reply. Here is what shows in the console:

    In bold are the description for each option

    If I put

    ACCOUNT PROCESSING MENU
    1. Create new account - empty account Option 1 creates the account
    2. Create new account - information available Option 2 Uses the account created and adds starting balance and starting interest rate
    3. Make deposit Option 3 Makes the deposit to the account created
    4. Make withdrawal Option 4 Makes a withdrawal from the account created
    5. Calculate monthly interest Option 5 Calculates the monthly interest
    6. View account balance Option 6 Lets you view users account balance
    7. Next available account number Option 7 Shows next available account
    8. Update monthly interest rate Option 8 Updates current interest rate to a new one
    9. Print account information Option 9 prints your whole account info (current balance and current interest rate)
    10. Exit

    Please enter you preferred option: 1
    Account # 12345 successfully created.
    Please enter you preferred option: 2
    Please enter your starting balance: 300
    Please enter the monthly interest rate: 3
    Account # 12345 successfully created.
    Please enter you preferred option: 3
    Please enter your deposit amount: 100
    Please enter you preferred option: 5
    Monthly interest earned: $0.0 <--- It should show the monthly interest earned
    Please enter you preferred option: 6
    Your account balance: $0.0 <--- Should show my current balance
    Please enter you preferred option: 7
    Next available account number: 12346
    Please enter you preferred option: 8
    What is the new monthly interest rate? 5
    Please enter you preferred option: 9
    Account number: 12345
    Account balance: $0.0 <--- Doesnt show current account balance nor interest.
    Monthly interest: $0.0
    Please enter you preferred option: 10
    Exiting Program.

    Now, If I put bankAccountUser = new BankAccount(); in option 1, it shows me the following error:

    Please enter you preferred option: 1
    Exception in thread "main" java.lang.NullPointerException
    at bankmenu.BankMenu.main(BankMenu.java:74)
    Java Result: 1

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,401
    Rep Power
    25

    Default Re: Help bank account assignment

    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. basic bank account
    By captain_turkiye in forum New To Java
    Replies: 5
    Last Post: 10-16-2011, 05:15 PM
  2. Adding Interest to a Bank Account
    By petur170 in forum New To Java
    Replies: 20
    Last Post: 05-26-2011, 02:28 AM
  3. Bank Account Project
    By Haal in forum New To Java
    Replies: 0
    Last Post: 03-20-2011, 07:30 PM
  4. java bank account problem
    By awil121 in forum New To Java
    Replies: 1
    Last Post: 10-13-2010, 10:47 PM
  5. Bank Account
    By HPcompaq256 in forum New To Java
    Replies: 11
    Last Post: 02-26-2010, 09:05 PM

Posting Permissions

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