lundi 20 juin 2016

How to Link File to Java Program means Searching a Database or record saved in a file

I have to submit my mini project on Atm by day after Tomorrow. I have completed d program for single user without using file but i have to convert d code for multi-user using files. Means for every user his username password and balance will be saved in a file. All i have to do is to ask d user to provide username and password and search this input in file to check if it is matching or not for a given record . If it is correct then we can proceed further for other operations like deposit,withdraw or check balance. I have to save record for min 50 users in a file .Can anyone guide me how to proceed the given Problem ? plz :(

Code for Single user is here : How can i modify it for multiuser ?

import java.util.Scanner;
import java.lang.String;

 abstract class ATM_USER
{
    static final String userName="ali";
    static final String passWord="786";
    static Double balance=50000.0;
    abstract public Boolean login(String x,String y);
    abstract public void deposit(Double d);
    abstract public void withdraw();
}

class TestDrive extends  ATM_USER
{
    public Boolean login(String x,String y)
    {
        if(x.equals(userName)==true && y.equals(passWord)==true)
            return true;
        else
        {
            System.out.println("wrong username or password");
            return false;
        }
    }
    public void deposit(Double d)
    {
        balance= balance+d;
        System.out.println("Cool, You have Successfully Deposited !");
    }
    public void withdraw()
    {
        Double wd;
        Scanner scan=new Scanner(System.in);
        System.out.println("Enter the amount to be withdrawn");
        wd= scan.nextDouble();
        if(wd>balance)
            System.out.println("Sorry ! You dont have required Balance !");

         else
          {
            balance=balance-wd;
            System.out.println("SuccessFull ! withdrawn money is "+wd+ "And Available balance is" + balance);
          } 
    }

    public static void main(String[] args) 
    {
        int choice;
        Double dep;
        TestDrive obj = new TestDrive();
        Boolean flag=false;
        while(flag==false){
        System.out.println("Enter user name and password");
        Scanner scan=new Scanner(System.in);
        String usr , pass;
        usr = scan.next();
        pass= scan.next();
        flag=obj.login(usr,pass);}
        if (flag==true)while(true){
            Scanner scan=new Scanner(System.in);
            System.out.println("Enter the choice 1.Deposit 2. withdraw 3.check Balance 4. Exit");
            choice=scan.nextInt();
            switch(choice)
            {
                case 1 : System.out.println("Enter the amount to be Deposited");
                         dep=scan.nextDouble();
                         obj.deposit(dep);
                         break;
                case 2 : obj.withdraw();
                         break;
                case 3 : System.out.println(" available balance is " +balance);
                         break;
                case 4 : return;
            }
          }
    }

}

Aucun commentaire:

Enregistrer un commentaire