Hi im trying to make a program which when you run acts like your talking to a robot who will asks some questions about your self but I have included a part where it asks you if you would like to continue but then i get stuck on how to make the program continue running or closing if the user inputs 'NO'. This is all my code so far:
/********************
*Husnain Sheraz
*06/08/17
*To test knowledge
*Home
********************/
import java.util.concurrent.TimeUnit;
import java.util.Scanner;
public class reviseJava{
public static void main(String[] args)
throws InterruptedException {
//Introduction just saying my name.
printWithDelays("Hello my name is HUS9.EXE", TimeUnit.MILLISECONDS, 100);
TimeUnit.SECONDS.sleep(2);
//Asking user's name and printing it.
//start a new line
System.out.println("");
Scanner scan = new Scanner(System.in);
//A prompt for the user to enter his name.
printWithDelays("What's your name?", TimeUnit.MILLISECONDS, 100);
//reads the next letters (string) the user presses before hitting enter.
String usersName = scan.nextLine();
//printing out the word hello and what ever the user inputted as his/hers name.
printWithDelays("Hello " + usersName, TimeUnit.MILLISECONDS, 100);
TimeUnit.SECONDS.sleep(1);
printWithDelays(" i'm going to ask you some basic questions about yourself. If you would like to continue please type 'YES' if you would not like to continue please type 'NO'.", TimeUnit.MILLISECONDS, 100);
printWithDelays("Would you like to continue?", TimeUnit.MILLISECONDS, 100);
String answer = scan.nextLine();
}
public static void printWithDelays(String data, TimeUnit unit, long delay)
throws InterruptedException {
for (char ch:data.toCharArray()) {
System.out.print(ch);
unit.sleep(delay);
}
}
}