java - I don't exactly know how .equalsIgnoreCase work? -


i literally know , hang of java right , i'm writing program helps records patient'd id in hospital, i'll show whole code first,then, tell will, here code

package hospitalsrecord; import java.util.*; import java.io.*; public class hospitalsrecord { public static scanner read = new scanner(system.in); public static arraylist namelist = new arraylist(); public static arraylist patientage = new arraylist(); public static arraylist disease = new arraylist(); public static arraylist datehospitalized = new arraylist(); public static arraylist roomnumber = new arraylist(); //adding patient function     public static void addnewpatient () {       //ask patient's name     system.out.println("please enter patient's name:");     string patientname = read.next();     //ask patient's age     system.out.println("please enter patient's age:");     int age = read.nextint();        //ask patient's illness     system.out.println("please enter patient's disease name (also include accidents eg. leg broke car accident):");     string illness = read.next();         //ask patient hospitalized date     system.out.println("please enter patient's hospitalized date(total days not included):");     string hptldate = read.next();         //ask patient's room number     system.out.println("please enter patient's hospitalize room number(3 degits):");     int hrn = read.nextint();     //confirmation     system.out.println("doctor, confirm following(y/n)?");     system.out.println("name:" + patientname);     system.out.println("age:" + age);     system.out.println("disease:" + illness);     system.out.println("date hospitalized (hptld):" + hptldate);     system.out.println("room number:" + hrn);     string confirm = read.next();     if (confirm.equals("y")) {       namelist.add(patientname);     patientage.add(age);     disease.add(illness);     datehospitalized.add(hptldate);     roomnumber.add(hrn);     } else {         addnewpatient();     }     }     //searching patient listed     public static void searchpatient (){      }     //remove patient function     public static void removepatient() {      }     //text printing function when strat program     public static void selectorpage(){         system.out.println("hello doctor, welcome hospital recorder v1.0.0");         system.out.println("if want add new patient recorder type: 'add' in next blank line line");         system.out.println("if want search patient list type: 'search' in next blank line");         system.out.println("and, if want remove patient out of hospitalizing type: 'remove' in next blank line");         option = read.next();     }     //text printing simmilar selecterpage function perform after function     public static void selecterpageafteraction() {         system.out.println("your action has been performed, doctor");         system.out.println("would perform action?(y/n)");        choiceselection = read.next();        if (choiceselection.equals("y")){         system.out.println("if want add new patient recorder type: 'add' in next blank line line");         system.out.println("if want search patient list type: 'search' in next blank line");         system.out.println("and, if want remove patient out of hospitalizing type: 'remove' in next blank line");         option = read.next();        }       }     //selection var     public static string option;     public static string choiceselection;     //main program     public static void main(string[] args) {         selectorpage();         switch (option) {             case("add"): {                 addnewpatient();                 break;             }             case("search"):{                 searchpatient();                 break;             }             case("remove"):{                 removepatient();                 break;             }             case("end"):{                 break;             }             default: {                 system.out.println("please enter indentified option");                 break;             }         }         if (option.equalsignorecase("end")){          }     }  } 

i hope guys can read every line because so so complex, can read of it, i'll know you'll still need more time hard working, no worry i'll spend sometime knowledge guys first, still working hard program complete while waiting answers! anyway point want guys focus @ point:

if (option.equalsignorecase("end")){      } 

it maybe blank because i've newly add while i'm working on it. so, want know @ if statement type option.equalsignorecase("end"), explain computer following?

1.compare the string variable options string"end"?

2.tell computer action inside if statement's when string option wasn't word end?

and please tell me how method work, don't understand it. understand "it compare 2 strings if wasn't same it's result true" know explanation wrong please me? again helping if can.

option.equalsignorecase("end") - equalsignorecase ignore whether string in lower case or uppercase.

so enter if block when option variable has either end or end.

your first assumption correct, asking compare string whether equal end. second 1 wrong, above code enter , execute statements present inside if when option end/end.

if want go inside if block when option not end add not if(!option.equalsignorecase("end")).

i hope clears doubt!


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -