Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am trying to validate the input of a user so when they enter an invalid provin

ID: 3614341 • Letter: I

Question

I am trying to validate the input of a user so when they enter an invalid province. In this case an invalid province isanything not NS or NL or NB. However, when l run this program it isnot even working. What am l doing wrong can someone please help

import javax.swing.*;

public class tatenda
{

public static void main (String [] geek )

    {

  
        Boolean keepgoing = true;

        String input ;


        while (keepgoing)
        {
           input=JOptionPane.showInputDialog("Enter the code of your province"+
        " Press q when you want toquit.");
        while (!input.equals("NS")||!input.equals("NB")||!input.equals("NL"))
        {
            input=JOptionPane.showInputDialog("Enter the code of yourprovince");
            JOptionPane.showMessageDialog(null, "You entered the wrongprovince");
        }




            if(input.equals("q"))
            {
               keepgoing=false;
            }
               else if(input.equals("NS")||input.equals("NB")||input.equals("NL"))
               {


                     System.out.print("I love You");
               }
}
}
}

Explanation / Answer

import javax.swing.*; public class Tatenda { public static void main (String [] geek ) {    Boolean keepgoing = true;    String input;    input=JOptionPane.showInputDialog("Enter thecode of your province" + " Press q when you want toquit.");         while(keepgoing)         {                     if(input.equals("NS")||input.equals("NB")||input.equals("NL"))                {            System.out.print("I love You");            keepgoing= false;                }                elseif(input.equals("q"))        {                keepgoing=false;            }                    // else    //while (!input.equals("NS")||!input.equals("NB")||!input.equals("NL"))        else       {        JOptionPane.showMessageDialog(null, "You entered the wrongprovince");        input=JOptionPane.showInputDialog("Enter the code of yourprovince");        }             } } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote