Hello i am trying to update a data of animals. Variables such as animalId, animal name, and animalNumber are used. In the Test part, to update an animal, the user will input their animmalId in which when the animal is found the editing part will appear and when the input is not found, a message will appear.
My problem is when the animalId inputted is not found, rather than displaying a message, it goes through the editing part and only then the error message will appear. How will I improve the if-else statement in the Test class of the program?
In the implementation class the code for this update method is as follows:
@Override
public String updateAnimal(Animal animal) {
if (animals.containsKey(animals.getId()))
{
animals.replace(animal.getId(), animal);
return "animal updated!";
}
else
{
return "can't find animal";
}
}
Code in the Test Class:
Animal a = new Animal
AnimalFx animal = service.getPort(AnimalFx.class);
Scanner input = new Scanner(System.in);
System.out.println("Enter Animal's ID: ");
String animals = input.next();
if(animals == null){
System.out.println(employee.updateAnimal(a));
}else{
System.out.println("\nUpdate Animal: " + animal.getAnimalDetails(animals).getName());
System.out.println("\nChange Animal Name: ");
String name = input.next();
a = new Animal();
a.setId(animals);
a.Name(animal.getAnimalDetails(animals).getName());
a.setAnimalNumber(animal.getAnimalDetails(animals).getAnimalNumber());
animal.updateAnimal(a);
System.out.println(animal.updateAnimal(a));
}
Aucun commentaire:
Enregistrer un commentaire