import java.util.*;
public class LabExer5B {
static Scanner scan = new Scanner(System.in);
static String [] Question = {"Which is the best Muzzle when controlling your recoil?", "Which is the best Muzzle to reduce the sound of a Gun?"};
static String [] Choices = {"a. Suppressor \nb. Compensator \nc. Flash Hider", "a. Flash Hider \nb. Compensator \nc. Suppresor" };
static String prompt = "Enter your Answer here: ";
static String UserAns;
private static String Answer1 = "b";
static int n = 1, CorrectAns = 0, QuestionsLeft = 10, attemptLeft = 3;
public static void main(String[] args) {
LabExer5B L = new LabExer5B();
L.Question1();
L.Question2();
}
public void Question1() {
while(n <=3) {
System.out.println(Question[0]);
System.out.println(Choices[0]);
System.out.print(prompt);
UserAns = scan.nextLine();
try {
if(UserAns.equalsIgnoreCase(Answer1)) {
CorrectAns = CorrectAns + 1;
QuestionsLeft--;
n += 3;
System.out.println("You are Correct! \nScore: " + CorrectAns + "\n" + QuestionsLeft + " Question(s) Left");
}
else if(!UserAns.equalsIgnoreCase(Answer1) && UserAns.equalsIgnoreCase("a") || UserAns.equalsIgnoreCase("b") || UserAns.equalsIgnoreCase("c")) {
QuestionsLeft--;
n+=3;
System.out.println("You are wrong!" +"\nScore: "+ CorrectAns + "\nQuestion(s) Left: " + QuestionsLeft);
continue;
}
if(!UserAns.equalsIgnoreCase("a") && !UserAns.equalsIgnoreCase("b") && !UserAns.equalsIgnoreCase("c")) {
throw new InvalidLetterException();
}
if(UserAns.isBlank() && UserAns.isEmpty() && UserAns == null) {
throw new EmptyStringException();
}
}
catch (InvalidLetterException ex) {
attemptLeft--;
System.out.println(ex.getMessage());
n++;
}
catch(EmptyStringException ex){
System.out.println(ex.getMessage());
}
}
}
public void Question2() {
System.out.println(Question[1]);
System.out.println(Choices[0]);
System.out.print(prompt);
UserAns = scan.nextLine();
}
class InvalidLetterException extends Exception{
public InvalidLetterException(){
super("Invalid Letter! \nPlease Enter a Valid Answer! \nYou only have " + attemptLeft + " attempt(s) Left");
}
}
class EmptyStringException extends Exception {
public EmptyStringException() {
super("Answer Cannot be Empty!");
}
}
class SpecialCharacterException extends Exception {
public SpecialCharacterException() {
super("Your Answer Cannot be Like That!");
}
}
}