I'd feel a little more comfortable answering this if I had the JDK setup on this computer and if I had more experience with Java, but I'll give it a shot anyway
Now you notice the program is asking you to continuously accept input until a user screws up twice. It doesn't specify whether the user's chances reset if they put in improper input and then put in proper input, but a user-friendly program would reset that tally for them, so we'll try to put that in too.
So your psuedo-code may look something like
while (true)
{
try
{
System.out.print("Enter a floating point number: ");
if (!in.hasNextDouble())
{
throw new BadDataException("Input needs to be a floating point number! Try again.");
}
else
{
data.add(in.nextDouble());
}
}
catch (BadDataException exception)
{
System.out.println("Bad data: " + exception.getMessage());
try
{
System.out.print("Enter a floating point number: ");
if (!in.hasNextDouble())
{
throw new BadDataException("Input needs to be a floating point number! Try again.");
}
else
{
data.add(in.nextDouble());
}
}
catch (BadDataException exception)
{
System.out.println("Bad data: " + exception.getMessage());
in.close();
}
}
}
I don't think you need a while loop for the program to pause while waiting for input, scanner should do that on its own. Then you just need to keep using try/catch until the user gets it right or runs out of chances, and keep on looping until you get to the exit point (Which I didn't account for, shouldn't be hard to put in there though)
Let me know if I'm totally wrong here, I'm not a Java expert lol