Question: 1 . Write the code to find the position of the smallest element in an array of integers 2 . Write the code to find

1. Write the code to find the position of the smallest element in an array of integers
2. Write the code to find the average of the elements in an array of integers
3. Create a dogArray static variable in an AnimalShelther class
4. Create the following two methods in the AnimalShelter class.
a. addAnimal(): this method accepts an Dog object and puts it into the dog array. Dont forget to increment the number of animals.
b. addAnimal(): an overloaded method that accepts the inputs needed to create a Dog instance. Instantiate a dog and add it to the array.
5. Modify the toString in the Dog class so that it prints the name and age separated by a space.
6. Modify the toString for the AnimalShelter class so that it prints all the animals in the shelter (dont delete what is already there, add to it).(You are going to be calling the toString() of the Dog class to help with this).
7. Create a driver class. Inside the main method, create a shelter variable, add at least one animal, and print the shelter. Experiment with adding more dogs to your shelter and printing the shelter.
8. Update the add methods to the AnimalShelter class in the Animal Shelter project to maintain a sorted collection.
9. Create a remove method in the AnimalShelter class that accepts an Animal to remove. This method should return true if the animal was in the collection and has been removed, and false if the animal was not in the collection. Make sure the collection stays sorted
10. Consider the following diagram
Check each of the statements that are logically and syntactically correct according to the structure diagram above.
a) Rodent rod = new Rat();
b) Rodent rod = new FieldMouse();
c) Mouse mou = new Rat();
d) Mouse mou = new Rodent();
e) Rat rat = new Rodent();
f) Rat rat = new LabRat();
g) Rat rat = new FieldMouse();
h) Rat rat = new Mouse();
11. Consider the following declarations
class Fruit{}
class Apple extends Fruit{}
class Orange extends Fruit{}
class GoldenDelicious extends Apple{}
class McIntosh extends Apple{}
public class Driver{
public static void main(String[] args){
Fruit f= new GoldenDelicious();
Orange o = new Orange();
}
}
Using the classes above, indicate each of the following statements that returns true.
a) System.out.println(f instanceof Fruit);
b) System.out.println(f instanceof Orange);
c) System.out.println(f instanceof Apple);
d) System.out.println(f instanceof GoldenDelicious);
e) System.out.println(f instanceof McIntosh);
f) System.out.println(o instanceof Orange);
g) System.out.println(o instanceof Fruit);
h) System.out.println(o instanceof Apple);
12. Fill in the blank
a) When two methods in the same class have the same name but different signatures it is called __________________
b) There are several methods with the same signature. When the correct method is chosen at runtime based on the type of the invoking object, it is called _____________________
c) When two methods in different classes have the same name and the same signatures it is called______________

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!