Results 1 to 2 of 2
  1. #1
    ihmflu is offline Member
    Join Date
    Mar 2012
    Posts
    1
    Rep Power
    0

    Thumbs down Need help for a Java homework mimic ATM Machine .

    write a java program using classes to mimic an ATM of a bank.

    The interactions are done with a menu.
    Save every accounts info in a text file using FileWriter and PrintWriter. Every withdrawal costs 20 cents.
    Sample MENU:
    WELCOME
    what do you want to do today?
    1.create a new account
    2.deposit into an existing account
    3.withdraw from an existing account
    4.check balance of an existing account
    5.print Summary of transactions
    6.exit

    Sample text file:
    Name: JOE , Balance = 120.80 $
    You have deposited 2 times with the amount of 10$
    You have withdraw 1 times with the amount of 5$
    You were charged 0.20$

    Name: Bob , Balance = 80.60 $
    You have deposited 2 times with the amount of 20$
    You have withdraw 2 times with the amount of 7$
    You were charged 0.40$

    ----------------------------------------------------------------------------
    So here is what I got for my main and class:



    // class
    import java.util.*;
    import java.text.*;
    import java.io.*;

    public class ATM
    {
    double input;
    double balance, withdraw, deposit;
    int number;
    double Deposit;
    double totalDeposit;
    double totalWithdraw;
    double totalCharge;
    int countDeposit;
    int countWithdraw;
    double charge;


    public String createAccount() throws IOException
    {
    String account;
    Scanner kb = new Scanner(System.in);
    System.out.print("Enter an account name you want to create.");
    account = kb.nextLine();
    System.out.println("Your account has been created. ");

    return account;
    }



    public void deposit(double dep)
    {

    balance += dep;
    countDeposit +=1;
    totalDeposit += dep;
    }

    public void withdraw(double w)
    {

    countWithdraw++;
    totalWithdraw +=w;
    balance -=0.20;
    balance -=w;
    charge += 0.20;
    }

    public double getBalance()
    {
    return balance;

    }
    public void setBalance(double sb)
    {
    balance = sb;
    }
    public double getCountDeposit()
    {
    return countDeposit;
    }
    public double getCountWithdraw()
    {
    return countWithdraw;
    }
    public double gettotalDeposit()
    {
    return totalDeposit;
    }
    public double getCharge()
    { return charge;
    }

    public double gettotalWithdraw()
    {
    return totalWithdraw;
    }

    }


    This is my main :

    import java.util.*;
    import java.io.*;
    import java.text.*;
    public class ATMTest
    {
    public static void main(String[] args) throws IOException
    {
    int number;



    DecimalFormat formatter = new DecimalFormat("#,###.00");
    ATM account = new ATM();

    Scanner kb = new Scanner(System.in);

    System.out.println("WELCOME! WHAT DO YOU WANT TO DO TODAY");



    while(true)
    {
    System.out.println("1.create a new account");
    System.out.println("2.deposit into an existing account");
    System.out.println("3.withdraw from an existing account");
    System.out.println("4.check balance of an existing account");
    System.out.println("5.print Summary of transactions");
    System.out.println("6.exit ");
    number= kb.nextInt();

    if(number ==1)
    {
    String newAccount = account.createAccount();
    }
    else if (number == 2)

    { System.out.println("How much do you want to deposit?");
    double deposit = kb.nextDouble();
    account.deposit(deposit);
    }

    else if (number == 3)
    {
    System.out.println("How much do you want to withdraw?");
    double withdraw = kb.nextDouble();

    if (withdraw > account.getBalance()){
    System.out.println("You don't have enough money to withdraw");
    }

    else
    {
    account.withdraw(withdraw);
    }


    }
    else if (number == 4)
    {

    System.out.println("Your balance is" + account.getBalance());
    }

    else if (number == 5)
    {
    System.out.println("your balance is");
    System.out.println("$" +account.getBalance());
    System.out.println("you have deposit: ");
    System.out.print(account.getCountDeposit() + "times");
    System.out.println("you have withdraw: ");
    System.out.println(account.getCountWithdraw()+ " times");
    System.out.println("you have deposit: ");
    System.out.println("$" + account.gettotalDeposit() );
    System.out.println("You have withdraw: ");
    System.out.println("$" +account.gettotalWithdraw() );
    System.out.println(" You were charged: ");
    System.out.println("$" + account.getCharge() );
    }
    else if (number == 6)
    System.exit(0);

    } //while loop

    }//main
    } //class


    It worked well but the thing is I don't know how to save the account to a text file and how to access to an existing account from the file. Can anyone please help?

  2. #2
    ojn
    ojn is offline Senior Member
    Join Date
    Aug 2008
    Location
    Stockholm, Sweden
    Posts
    119
    Rep Power
    0

    Default Re: Need help for a Java homework mimic ATM Machine .

    Google search: Java read write file
    Also, put your code in CODE tags, if you want anyone to read it. And finally, ask a specific question. "How do I do.." is not one.

Similar Threads

  1. Using JOptionPane to mimic calculator
    By kjones9687 in forum New To Java
    Replies: 8
    Last Post: 02-16-2012, 09:45 AM
  2. Replies: 0
    Last Post: 02-07-2011, 01:27 PM
  3. java homework help
    By jenniferrlie in forum New To Java
    Replies: 5
    Last Post: 09-22-2009, 08:12 PM
  4. Java homework please
    By Indulgence in forum New To Java
    Replies: 1
    Last Post: 11-03-2008, 02:48 AM
  5. LF: Homework help with Java
    By excurssion in forum New To Java
    Replies: 2
    Last Post: 10-17-2008, 06:00 AM

Posting Permissions

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