Hello. I am writing an ATM program for a project, but I am having problems matching the users entered pin with what is stored on the text file. Here is how i read the file
import java.io.File;
import java.util.Scanner;
import machine.*;
import javax.swing.JOptionPane;
public class FileRead
{
Transactions query = new Transactions ();
private Scanner read;
private String pin;
public void setPin ( String number )
{
pin = number;
}
public String getPin ()
{
return pin;
}
public void openFile ()
{
try
{
read = new Scanner( new File ( "Customers.txt" ) );
}
catch ( Exception e )
{
JOptionPane.showMessageDialog( null, "Customer does not exsist" );
}
}
public void readFile ()
{
String input1 = "holding_name";
String input2 = "holding_pin#";
String input3 = "holding_balance";
while (read.hasNext())
{
input1 = read.next();
input2 = read.next();
input3 = read.next();
if ( input2.equals(pin) )
{
query.setBalance(input3);
JOptionPane.showMessageDialog( null,String.format("Balance has $%s", query.getBalance()));
}
}
}
public void closeFile ()
{
read.close();
}
}
Now when the program gets to this part I find that the pin is set. However, the set balance does not receive any data.What am I doing wrong, is it my "while" statement that needs help?