i was tasked with writing a program that prints the question ”Do you want to continue?” and reads a
user input. If the user input is ”Y”, ”Yes”, ”OK”, ”Sure”, or ”Why not?”, print out ”OK”. If
the user input is ”N” or ”No”, then print out ”Terminating”. Otherwise, print ”Bad input”.
The case of the user input should not matter. For example, ”y” or ”yes” are also valid
inputs.

Write a class YesNoChecker for this purpose

i made a class continue

import java. util.Scanner; 


public class Continue 
{ 
public static void main(String[] args) 
{ 
Scanner in = new Scanner(System.in); 
System.out.println("Do you want to continue?"); 

String input = in.nextLine(); 
YesNoChecker c = new YesNoChecker(input); 

if(c.isYes()) 
System.out.println("OK"); 
else if (c.isNo()) 
System.out.println("Terminating"); 
else 
System.out.println("Bad Input") ; 
} 
}

now comes the problem im facing i dont know how to get started on the methods .isYes and .isNo please be kind enough to give me some guidance thank you

public class YesNoChecker {



    public void YesnoChecker(String a){



    }

    public String isYes(){


    }

        public String isNo(){




    }

Your methods need to return a boolean (true or false) not a String if you want to call and use them like you do in lines 14 and 16.

The String class has methods equals and equalsIgnoreCase. You can find the details in the Java API documentation here

For example: you can use equalsIgnoreCase inside an if test to see if the String is Yes yes or YES. Similarly you can use a second if to test for Sure sure or SURE. When you find a match you can return true from your method. If you have tested all the possiblities and not found a match you can return false.

Try writing the code, and see how it goes. YOu;ll need to do a bit of research and some trial-and-error, but that's how people learn!

switch (x.toUpperCase) {
case "YES":
   ...
   break;
case "NO":
   ...
   break;
...
}

much clearer overall than a jungle of nested if statements.
Just about the only thing added to the Java language I like since generics.

This article has been dead for over six months. Start a new discussion instead.