My code simply asks the user to enter data for a file. I want to ask them every time if they want to add a new record before doing the process. Following is my code.
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Assign11 {
    public static void main(String[] args) throws IOException{
        Scanner keyboard = new Scanner (System.in);
        System.out.println("enter FILE name");
        String FileName = keyboard.nextLine();
        FileWriter fwriter = new FileWriter(FileName);
        PrintWriter StudentFile = new PrintWriter(fwriter);
        String name = "";
        int age = 0;
        double gpa = 0.0;
        String answer = "";
        do {
                System.out.println("Enter name.");
                name = keyboard.nextLine();
                System.out.println("Enter age.");
                age = keyboard.nextInt();
                keyboard.nextLine();
                System.out.println("Enter GPA.");
                gpa = keyboard.nextDouble();
                StudentFile.println (name);
                StudentFile.println (age);
                StudentFile.println (gpa);
                System.out.println("Do you wish to enter a new record? "
                            + "Type 'y' or 'n'.");
                answer = keyboard.nextLine();
        } 
        while (answer.equalsIgnoreCase("y"));
        StudentFile.close();
        System.exit(0);
    }
}
But the problem is that the question of adding a new record doesn't asked to user. So I was wondering what I did wrong and how I could fix it.
 
    