tabel69 0 Newbie Poster

Hi out there.

I have a project that I just cant seem to get to work. I just don't get programming! I have been working on this for three days, and all I am doing is going in circles. I can't seem to get the array to initialize.

The assignment: Use the Account classes created earlier to simulate an ATM machine. Create ten account in an array with id 0,1,...9, and initial balance $100.00. The system prompts the user to enter an id. if the id is enter incorrectly, ask the user to enter a corect id. Once an id is accepted, the main menus is displace. You can enter choice 1 for viewing balance, 2 for withdraw money, 3 for deposit and 4 to exit.

my code:

import java.util.*;

public class ATM {
     public class Account {
    private int id;
    private double balance;
    private double annualInterestRate;
    private final Date dateCreated = new Date();

    public Account() {
    }

    public Date getDateCreated() {
        return dateCreated;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getId() {
        return id;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public double getBalance() {
        return balance;
    }

    public void setAnnualInterestRate(double annualInterestRate) {
        this.annualInterestRate = annualInterestRate;
    }

    public double getAnnualInterestRate() {
        return annualInterestRate;
    }

    public void deposit(double amount) {
        balance += amount;
    }

    public void withdraw(double amount) {
        deposit(- amount);
    }

    public double getMonthlyInterestRate() {
        return getAnnualInterestRate()/12;
    }


}

    public static void main(String[] args)
     {
	
	int currentAccountId;
	int currentChoice;
	double moneyVariable;
	boolean customerLoopFlag;
        boolean validcurrentAccountID;
        boolean validcurrentChoice;

        Scanner input = new Scanner(System.in);

      //initialize the array of accounts
        Account[] customerAccount = new Account[10];
        for (int i = 0; i < 10; i++)
                {
		customerAccount[i] = new Account();
		customerAccount[i].setId(i);
		customerAccount[i].setBalance((double)100);
		}
  //Get user data about account
        do
        {
        System.out.println( "Enter an account number between 0 and 9: ");
        currentAccountId = input.nextInt();
        validcurrentAccountID = true;
             if ( (currentAccountId < 0)  || (currentAccountId > 9))
                 {
                 validcurrentAccountID = false;
                 System.out.println( "Please enter a valid account number between 0 and 9: ");
                 }
                    }while (!validcurrentAccountID);
                          //print customer menu
			System.out.println("");
			System.out.println("Main menu:");
			System.out.println("1: Check Balance");
			System.out.println("2: Withdraw");
			System.out.println("3: Deposit");
			System.out.println("4: Exit");

			System.out.print("Enter a choice: ");
                        currentChoice = input.nextInt();
                        validcurrentChoice = true;
                            if ( (currentChoice < 0) || (currentChoice >= 4));//check to make sure it is in the range
                            {
                               validcurrentChoice = false;
                               System.out.println( "Please enter a valid choice between 1 and 4: ");
                            }
                                }while (!validcurrentChoice);

                                switch (currentChoice)
                                {
                                case 1:
                                    System.out.println("Current Balance is: " + getID.getBalance());
                                    break;
                                case 2:
                                    System.out.print("Enter ammount to withdraw: ");
                                    moneyVariable = input.nextDouble();
                                    customerAccount[customerAccount].withdraw(moneyVariable);
                                    break;
                                case 3:
                                    System.out.print("Enter ammount to deposit: ");
                                    moneyVariable = input.nextDouble();
                                    customerAccount[customerAccount].deposit(moneyVariable);
                                    break;
                                case 4:
                                    customerLoopFlag = false;
                                    break;
		
			}

    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.