Hello Daniweb.
I am trying to make an application for a ATM machine (class homework).
This is the schematic that I followed
http://www.screencast.com/users/haxtor21/folders/Jing/media/303e583a-8f90-46f3-8ed1-a35dde2200bb
My issue is that I'm trying to access a text file and search for a account ID. After the account ID i am doing a nextDouble and storing the next value, which is the balance, in the balance variable. I tried using findInLine to find the acctID but the compiler is telling me its only usable for strings.
So the text file would look like this
acct ID $
"
567 1020
897 2356
"
Here is what I have so far:
import java.io.*;
import javax.swing.*;
import java.util.*;
public class ATM{
static Scanner in= new Scanner(System.in);
static int acctID;
static double balance;
public static void main(String[] args){
int identif=0;
String tranType, findID, evalTran, transaction=null, findIden=null;
double amount, dollars=0;
//From customer
acctID= getAcctID(identif);
tranType= getTranType(transaction);
//Bank ID validation and Balance declaration
findID= validateID(findIden);
//Evaluating the transaction
evalTrans= evaluate();
}
public static int getAcctID(int acctID){
System.out.println("Enter your account ID(###): ");
acctID= in.nextInt();
return acctID;}
public static String getTranType(String transType){
System.out.println("Would you like to Deposit(d) or Withdrawl(w) an amount?");
String tranType= in.nextLine();
return tranType;}
public static String validateID(String findIden){ //Finds the BankIDs file, looks for the acctID
File bankIds=new File("BankIDs.txt"); //and the cursor moves there
Scanner id=new Scanner(bankIds);
id.findInLine(acctID);
if(id.hasNext()){ //If there is a number (the balance) after acctID
balance= id.nextDouble();} //then use that number as the balance
else{ //otherwise exit the program and the program will restart
System.out.println("Sorry, your bank ID is invalid");//asking the user for his acctID again
System.exit(0);}
id.close();}
public static void evaluate(){
System.out.println("What amount would you like to transfer?");
double amount= in.nextDouble();
if(tranType.equalsCaseIgnore(w)){
if(balance>=amount)
balance-=amount;
else
System.out.println("Sorry, you do not have that many funds available");}
else
balance+=amount;
}
}
Any other tips for my code would be appreciated.