We are working on a group task. Part of the program is intended to be used to enter “payment”, followed by the SIN student number (social security number) and how much to deduct their account. Eg pay,193678187,900.
SIN SIN is compared with a list of files generated by the array and compares curSin.equals(stuSin)). curSinand stuSinare strings.
If a SIN is found, it will reduce the number of elements from the student’s balance (not shown) and write it to a file write(student,inrec).
If the SIN is not found, it should return "SIN not found."
Our problem is that even if a SIN is found, it still returns "SIN not found". We believe that this has something to do with the if statement, and the comparison is not equal, but we tried everything we can think about and cannot make it work properly.
Any help would be greatly appreciated. Thank.
Below is a snippet of code.
if (cmd.equals("pay") && p.length == 3)
{
System.out.println("pay");
String stuSin = p[1];
double stupay = Double.parseDouble(p[2]);
for (int i = 0; i < student.length; i++)
{
Student x1 = student[i];
String curSin = x1.getSin();
if (curSin.equals(stuSin))
{
double curpay = x1.getBal();
double newBal = curpay - stupay;
if (stupay > curpay)
{
JOptionPane.showMessageDialog(null, "Overpayment");
System.exit(0);
}
x1.setBal(newBal);
System.out.println(x1.getBal());
write(student, inrec);
}
else if (!curSin.equals(stuSin))
{
JOptionPane.showMessageDialog(null, "SIN not found");
System.exit(0);
}
}
}
source
share