I want to update a record of a gym member when his/her weight change. But unfortunately my program can't find the given member.
Here is my code:
public static void updateWeight()
{
Scanner in = new Scanner(System.in); // Creation of a new Scanner object
String tempName = ""; // Store temporary name collected by Scanner objecgt
String tempLastName = ""; // Store temporary last name collected by Scanner object
boolean found = false; // Boolean value in the case tha a member is found
int i = 0;
//Message to be displayed on the screen to input the values of tempName and tempLastName
System.out.println(" Give first name and last name of the member you want to change the weight separated with a space .");
String line = in.nextLine();
String[] split = line.split(" ");
tempName = split[0];
tempLastName = split[1];
//System.out.println(tempName + " " + tempLastName);
ListIterator itr = GymList.listIterator();
while(itr.hasNext())
{
if( (tempName.equals(GymList.get(i).getFirstName())) && (tempLastName.equals(GymList.get(i).getLastName())))
{
System.out.print(" Give new value for weight in kg: "); //Ask for new weight value
GymList.get(i).setWeight(in.nextDouble()); //Set new weight
found = true; // change boolean value to true
break;
}
itr.next(); // move iterator to next position
i++; // increment counter
}
//if member found
if(found)
{
System.out.println(); //Empty line
System.out.print(" Updated data: "); //Message
//Display updated data
System.out.println(GymList.get(i).getFirstName() + " " + GymList.get(i).getLastName() + " " +
GymList.get(i).getWeight() + " " + GymList.get(i).groupBMI());
}//in case that member is not found
else
{
System.out.println(" No such member! ");
}
}