I need help creating a method that takes input from users, and then searches an array to see if the input is present in the array.   Attatched is what I have so far. It is incorrect because no matter what input is recieved, it will output as "New Patient".  Need help revising.

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter7: Using Methods
Section: Chapter Questions
Problem 20RQ
icon
Related questions
Question
100%

I need help creating a method that takes input from users, and then searches an array to see if the input is present in the array.

 

Attatched is what I have so far. It is incorrect because no matter what input is recieved, it will output as "New Patient".  Need help revising.

boolean newPatient;
String Animal;
String Breed;
String Name;
int age;
Double weight;
String appointmentDate;
String appointmentTime;
String[] animallist={"Benny","Princess", "Issabella", "Kovu","Samson", "Spot"};
public void enterPatient() { //A method asks for patient name and searches through an existing array to see if they are existing patient.
int i;
Scanner animalName = new Scanner(System.in);
System.out.println("Enter Animal Name"); //Asking to enter Animal name
for (i=0;i <animallist.length; i++){ //Looking through animallist array to see if there is a match
if (animallist[i] ==animalName.nextLine()){
System.out.println("Existing Patient");
}
else {
System.out.println("New Patient");
}
Transcribed Image Text:boolean newPatient; String Animal; String Breed; String Name; int age; Double weight; String appointmentDate; String appointmentTime; String[] animallist={"Benny","Princess", "Issabella", "Kovu","Samson", "Spot"}; public void enterPatient() { //A method asks for patient name and searches through an existing array to see if they are existing patient. int i; Scanner animalName = new Scanner(System.in); System.out.println("Enter Animal Name"); //Asking to enter Animal name for (i=0;i <animallist.length; i++){ //Looking through animallist array to see if there is a match if (animallist[i] ==animalName.nextLine()){ System.out.println("Existing Patient"); } else { System.out.println("New Patient"); }
n:
MedicalFormDemo x
"C:\Program Files\Amazon Corretto\jdk11.0.9_12\bin\java.exe"
Enter Animal Name
Sally
New Patient
2 Maple
New Patient
Benson
New Patient
Princess
New Patient
|
Transcribed Image Text:n: MedicalFormDemo x "C:\Program Files\Amazon Corretto\jdk11.0.9_12\bin\java.exe" Enter Animal Name Sally New Patient 2 Maple New Patient Benson New Patient Princess New Patient |
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT