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: What is wrong with my codes. it s not running. Pls help cos i have to present on the 2nd of December

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation What is wrong with my codes. it s not running. Pls help cos i have to present on the 2nd of December

    // ATM.java


    public class completeAtm
    {
    private boolean userAuthenticated; // whether user is authenticated
    private int currentAccountNumber; // current user's account number
    private Screen screen; // ATM's screen
    private Keypad keypad; // ATM's keypad
    private CashDispenser cashDispenser; // ATM's cash dispenser
    private DepositSlot depositSlot; // ATM's deposit slot
    private BankDatabase bankDatabase; // account information database

    // constants corresponding to main menu options
    private static final int BALANCE_INQUIRY = 1;
    private static final int WITHDRAWAL = 2;
    private static final int DEPOSIT = 3;
    private static final int EXIT = 4;

    // no-argument ATM constructor initializes instance variables
    public ATM()
    {
    userAuthenticated = false; // user is not authenticated to start
    currentAccountNumber = 0; // no current account number to start
    screen = new Screen(); // create screen
    keypad = new Keypad(); // create keypad
    cashDispenser = new CashDispenser(); // create cash dispenser
    depositSlot = new DepositSlot(); // create deposit slot
    bankDatabase = new BankDatabase(); // create acct info database
    } // end no-argument ATM constructor

    // start ATM
    public void run()
    {
    // welcome and authenticate user; perform transactions
    while ( true )
    {
    // loop while user is not yet authenticated
    while ( !userAuthenticated )
    {
    screen.displayMessageLine( "\nWELCOME TO GREAT INVESTMENT BANK!" );
    authenticateUser(); // authenticate user
    } // end while

    performTransactions(); // user is now authenticated
    userAuthenticated = false; // reset before next ATM session
    currentAccountNumber = 0; // reset before next ATM session
    screen.displayMessageLine( "\nThank you! Goodbye!" );
    } // end while
    } // end method run

    // attempts to authenticate user against database
    private void authenticateUser()
    {
    screen.displayMessage( "\nPlease enter your account number: " );
    int accountNumber = keypad.getInput(); // input account number
    screen.displayMessage( "\nEnter your PIN: " ); // prompt for PIN
    int pin = keypad.getInput(); // input PIN

    // set userAuthenticated to boolean value returned by database
    userAuthenticated =
    bankDatabase.authenticateUser( accountNumber, pin );

    // check whether authentication succeeded
    if ( userAuthenticated )
    {
    currentAccountNumber = accountNumber; // save user's account #
    } // end if
    else
    screen.displayMessageLine(
    "Invalid account number or PIN. Please try again." );
    } // end method authenticateUser

    // display the main menu and perform transactions
    private void performTransactions()
    {
    // local variable to store transaction currently
    Transaction currentTransaction = null;
    boolean userExited = false; // user has not chosen to exit

    // loop while user has not chosen option to exit system
    while ( !userExited )
    {
    // show main menu and get user selection
    int mainMenuSelection = displayMainMenu();

    // decide how to proceed based on user's menu selection
    switch ( mainMenuSelection )
    {
    // user chose to perform one of three transaction types
    case BALANCE_INQUIRY:
    case WITHDRAWAL:
    case DEPOSIT:

    // initialize as new object of chosen type
    currentTransaction =
    createTransaction( mainMenuSelection );

    currentTransaction.execute(); // execute transaction
    break;
    case EXIT: // user chose to terminate session
    screen.displayMessageLine( "\nExiting the system..." );
    userExited = true; // this ATM session should end
    break;
    default: // user did not enter an integer from 1-4
    screen.displayMessageLine(
    "\nYou did not enter a valid selection. Try again." );
    break;
    } // end switch
    } // end while
    } // end method performTransactions

    // display the main menu and return an input selection
    private int displayMainMenu()
    {
    screen.displayMessageLine( "\nMain menu:" );
    screen.displayMessageLine( "1 - View my balance" );
    screen.displayMessageLine( "2 - Withdraw cash" );
    screen.displayMessageLine( "3 - Deposit funds" );
    screen.displayMessageLine( "4 - Exit\n" );
    screen.displayMessage( "Enter a choice: " );
    return keypad.getInput(); // return user's selection
    } // end method displayMainMenu

    // return object of specified Transaction subclass
    private Transaction createTransaction( int type )
    {
    Transaction temp = null; // temporary Transaction variable
    //determine which type of Transaction to create
    switch ( type )
    {
    case BALANCE_INQUIRY: // create new BalanceInquiry transaction
    temp = new BalanceInquiry(
    currentAccountNumber, screen, bankDatabase );
    break;
    case WITHDRAWAL: // create new Withdrawal transaction
    temp = new Withdrawal( currentAccountNumber, screen,
    bankDatabase, keypad, cashDispenser );
    break;
    case DEPOSIT: // create new Deposit transaction
    temp = new Deposit( currentAccountNumber, screen,
    bankDatabase, keypad, depositSlot );
    break;
    } // end switch

    return temp; // return the newly created object
    } // end method createTransaction
    } // end class ATM


  2. #2
    Member
    Join Date
    Nov 2013
    Location
    Bangalore, India
    Posts
    70
    My Mood
    Cool
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Default Re: What is wrong with my codes. it s not running. Pls help cos i have to present on the 2nd of December

    Please post the error you see on the console.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,075
    My Mood
    Mellow
    Thanks
    184
    Thanked 652 Times in 639 Posts

    Default Re: What is wrong with my codes. it s not running. Pls help cos i have to present on the 2nd of December

    Please read the Announcement topic (a new user FAQ) to learn how to post your code correctly along with other useful tips for newcomers. Then edit or repost (in the same thread) your corrected question with the details necessary to help you.

  4. #4
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What is wrong with my codes. it s not running. Pls help cos i have to present on the 2nd of December

    hi

Similar Threads

  1. cos(x) program
    By anon314 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 6th, 2013, 11:53 AM
  2. Ludum Dare 22: December 16-18
    By KevinWorkman in forum The Cafe
    Replies: 9
    Last Post: December 8th, 2011, 12:35 PM
  3. I cannot get this loop to stop running. What am I doing wrong??
    By Nismoz3255 in forum Loops & Control Statements
    Replies: 2
    Last Post: May 1st, 2011, 10:28 PM
  4. Please Help What's Wrong with my Codes!
    By bertzki10 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 25th, 2011, 10:03 AM