0

Array in Java

I have to make a Dog list class that is in an array form, I need to have an adding method that adds a dog to my list (array) I need to have a removing method that removes a dog from my list(array) I also need to check if a dog exists in my list (array) Please help me out with the methods I have a hard time knowing How to make them work

3rd Jan 2023, 12:47 AM
Melissa 123
Melissa 123 - avatar
4 Answers
+ 2
You would have a field in your DogList class to store all the dogs: private List<Dog> dogList = new ArrayList<>(); Your method signatures might look like this: void addDog(Dog dog) { } void removeDog(Dog dog) { } boolean dogExists(Dog dog) { }
3rd Jan 2023, 3:12 AM
Tibor Santa
Tibor Santa - avatar
+ 2
If you have an array of dogs, then you can loop through the array and check each element if it equals to the dog that you are looking for.
3rd Jan 2023, 10:53 AM
Tibor Santa
Tibor Santa - avatar
0
we are allowed only to use Array . Yes I did those basics but I don’t know whst to put in the methods you know how can I check if a dog exisys for example.
3rd Jan 2023, 10:38 AM
Melissa 123
Melissa 123 - avatar
0
Thanks guys I git help but it was difficuly I will get back to ask aclarations
10th Jan 2023, 2:27 AM
Melissa 123
Melissa 123 - avatar