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 2 of 2

Thread: Having problem to read the data inside txt

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

    Default Having problem to read the data inside txt

    Write an application that simulates a simple Bank Automated Teller Machine (ATM).
    This application provides a menu that allows a user to select the following operations:

    Withdrawal
    Deposit
    Check Balance

    Other requirements:
    -Add an extra choice to let the user quit the system.
    -After every withdrawal and deposit, display the current balance.
    -Withdraw amount must be:
    Less than or equal to current balance
    In multiple of 10 (e.g amount of 1034.00 is not allowed)
    -Before the menu is displayed, the user is authenticated by reading the account number and the pin number. The account number and the pin number enterd by the user must match with the account number and the pin number of the user account.
    - Create a BankAcount object for every customer. Each BankAccount object contains:
    - An account number
    - The account’s owner name
    - The pincode
    - The account balance amount
    - All relevant methods for a bank account (such as the getters & setters method, withdraw, deposit & checkbalance and the constructor.
    - All values for every BankAccount objects are read and stored in a textfile.


    BankAcc.txt
    This is my user from the Bank , but i only can read the first person detail from this txt. Means, Afiq Bin Ahmad only.
    Then how i going to read the second or the third user information(bank account number and pincode) ? For Cheah Soon Kit and David Krishnan?

    Now my code is :
    import java.util.*;
    import javax.swing.JOptionPane;
    import java.io.*;

    public class ATMProject
    {
    public static void main(String[] args)throws IOException

    {
    int number = 1;
    int choice = 0 ;
    Scanner scan = new Scanner(System.in);

    drawLine ("=");
    System.out.println (" Bank Of Malaysia ");
    drawLine ("=");

    System.out.print("Enter your account number> ");
    String search = scan.nextLine();

    System.out.print("Enter your pincode> ");
    String searchString = scan.nextLine().toLowerCase();

    File file = new File("BankAcc.txt");

    FileReader fileReader = new FileReader(file);
    BufferedReader bufReader = new BufferedReader(fileReader);

    String name,AccNum,pinCode;
    String balance;

    name=bufReader.readLine();
    AccNum=bufReader.readLine();
    pinCode=bufReader.readLine();
    balance=bufReader.readLine();

    double i = Double.parseDouble(balance);


    if ((search.equals(AccNum)) && (searchString.equals(pinCode)))
    {
    drawLine ("=");
    System.out.println ("Welcome " + name);
    drawLine ("=");
    selection();

    do {
    try {
    choice = printMenu();
    if (choice == 1 ) {
    drawLine("-");
    System.out.println("Withdrawing.....");
    System.out.print ("Enter the amount to withdraw> ");
    double withdraw = scan.nextDouble();
    System.out.println ("Withdrawal successful");
    i=i-withdraw;

    System.out.println ("your balance now is=" +i);
    drawLine("-");
    selection();

    } else if (choice == 2 ) {
    drawLine("-");
    System.out.println("Depositing.....");
    System.out.print("Enter the amount to deposit> ");
    double deposit= scan.nextDouble();
    i=i+deposit;

    System.out.println ("your balance now is " + i);
    drawLine("-");
    selection();

    } else if (choice == 3) {
    drawLine("-");
    System.out.println("Checking Balance......");
    drawLine("-");
    selection();

    } else if (choice == 4) {
    System.out.println("Bye....");

    } else {
    System.out.println("You have chosen invalid input!Try again..");
    }
    }catch (Exception e){
    }

    } while (choice != 4);

    }
    else
    {
    System.out.println("Incorrect Account number and pinCode");
    }

    bufReader.close();

    }

    public static void drawLine() {
    System.out.println("+++++++++++++++++++++++++++");
    }

    public static void selection (){
    System.out.println (" please make your selection in the menu");
    }

    public static void drawLine(String symbol) {
    for (int i=1; i<=30; i++) {
    System.out.print(symbol);
    }
    System.out.println();
    }

    public static int printMenu() {
    String choice =JOptionPane.showInputDialog ("1. Withdraw\n2. Deposit\n3. Check balance\n4. Exit");
    int choiceInt = Integer.parseInt(choice);
    return choiceInt;
    }
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Having problem to read the data inside txt

    Please read this topic to learn how to post code correctly so that it retains its formatting and is more easily readable.

    In programming, the technique used to do nearly the same thing one or several times is to enclose the code that does that thing in a loop with a condition specified that causes it to do its thing the correct number of times and then exit when done. Are you familiar with loops? do/while, for, and while loops are the common ones. In your case, a while loop would be appropriate.

Similar Threads

  1. Replies: 1
    Last Post: October 30th, 2013, 09:55 PM
  2. how to read and execute the whole .txt file
    By epulcipun in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: March 21st, 2013, 03:18 PM
  3. Replies: 3
    Last Post: March 21st, 2013, 10:12 AM
  4. How can I read txt files in java program??
    By sakura_smile in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 9th, 2012, 06:18 PM
  5. Read .txt file and create objects using data
    By sevans20 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: April 14th, 2012, 01:52 PM