Ich bin im wahrsten Sinne des Wortes und bekomme den Dreh raus und ich schreibe das Programm, das hilft, den Patientenausweis im Krankenhaus aufzuzeichnen, ich zeige zuerst den ganzen Code, dann erzähle ich dir so will, hier ist der CodeIch weiß nicht genau, wie .equalsIgnoreCase funktioniert?
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 by 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, would you like to confirm the 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 that listed
public static void searchPatient(){
}
//remove the patient function
public static void removePatient() {
}
//text printing function when strat the program
public static void selectorPage(){
System.out.println("Hello Doctor, welcome to Hospital Recorder v1.0.0");
System.out.println("If you want to add new patient into this recorder type: 'add' in the next blank line line");
System.out.println("If you want to search the patient list type: 'search' in the next blank line");
System.out.println("And, if you want to remove the patient that was out of hospitalizing type: 'remove' in the next blank line");
option = read.next();
}
//text printing simmilar to selecterPage function but perform after function
public static void selecterPageAfterAction() {
System.out.println("Your action has been performed, doctor");
System.out.println("Would you like to perform another action?(y/n)");
choiceSelection = read.next();
if (choiceSelection.equals("y")){
System.out.println("If you want to add new patient into this recorder type: 'add' in the next blank line line");
System.out.println("If you want to search the patient list type: 'search' in the next blank line");
System.out.println("And, if you want to remove the patient that was out of hospitalizing type: 'remove' in the 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 the indentified option");
break;
}
}
if (option.equalsIgnoreCase("end")){
}
}
}
ich hoffe, euch jede Zeile lesen kann, weil es so so so so komplex war, aber für jemanden, der alle es lesen kann, werde ich wissen, dass Sie sagen, ich werde benötige immer noch mehr Zeit für hartes Arbeiten, keine Sorge, ich werde irgendwann das meiste Wissen von euch Kerlen ausgeben, aber immer noch hart arbeiten, damit das Programm fertig ist, während du auf Antworten wartest! ohnehin der Punkt, den ich will euch an dieser Stelle konzentrieren:
if (option.equalsIgnoreCase("end")){
}
Es ist vielleicht zu leeren, weil ich habe es gerade neu hinzufügen, während ich daran arbeite. Also, was ich wissen möchte, ist an der if-Anweisung Ich tippe option.equalsIgnoreCase ("Ende"), erkläre ich dem Computer, um folgendes zu tun?
1.Vergleichen Sie die Variablen der String-Variablen mit dem String "end"?
2.Tell den Computer, um die Aktion innerhalb if-Anweisung zu tun, wenn die String-Option nicht das Wort Ende war?
Und bitte sagen Sie mir, wie diese Methode funktioniert, ich verstehe es nicht klar. Ich verstehe so "Es vergleicht zwei Strings, wenn es nicht das gleiche ist, dann ist das Ergebnis wahr" Ich weiß, dass meine Erklärung falsch ist, also könntest du mir bitte helfen? Nochmals vielen Dank für Ihre Hilfe, wenn Sie können.
Der zufällige 'String' Vergleich mit' String # equals' ist Groß-und Kleinschreibung, diese Methode vergleicht diese beiden 'String' Groß-und Kleinschreibung. – SomeJavaGuy
Um weiter zu klären ... Vergleichen von "Alpha" und "Alpha" mit String # equals wird false zurückgeben, da 'A' nicht gleich 'a' ist. Aber der Vergleich von "Alpha" mit "Alpha" unter Verwendung von String # equalsIgnoreCase gibt True zurück, weil "A" gleich "a" ist, wenn Sie Groß-/Kleinschreibung ignorieren. – Madhusudhan
Die Methode gibt nur wahr zurück, wenn beide Zeichenfolgen gleich sind, während die Groß-/Kleinschreibung der Zeichenfolgen ignoriert wird. '" TRUE ".equalsIgnoreCase (" true ");' hat das Ergebnis 'true'. – Patrick