---
tags: Setup-Summer21
---
# Lecture 4 Setup/Prep
In lecture 4, we will learn
- how to share helper functions and common fields across classes
We will continue building on the `Dillo`, `Boa`, and `Zoo` example from lecture 3. Download the [starter zip file for `lec04`](https://cs18-summer-2021.github.io/static/classes/4/lec04.zip). You can unzip this into your lectures project's `src` directory within IntelliJ.
Remember to use `Right-Click-on-lec03 -> Mark Directory As -> Excluded` to hide your `lec03` directory while we work on `lec04`.
## Prep
Last class, we saw the idea of an *interface* as the way to create a new type name in Java.
We also began to look at how to define a method (`isNormalSize`) that could work on either `Dillo` or `Boa` objects. At the very end of class, we put a version of that method in each of the two classes, and added it to the interface. This code is in the starter zip.
In lecture 4, we will:
- work through why we list method names in interfaces
- see how to handle code that is repeated across classes
In lecture 4, we'll build on that idea to better understand Java types, and add a helper function that should work with both `Dillo` and `Boa`.
We will work towards getting a well-designed Java program that supports the following `healthCheck` method in the `Zoo` class:
```
public class Zoo {
IAnimal animal1;
IAnimal animal2;
public Zoo(IAnimal ani1, IAnimal ani2) {
this.animal1 = ani1;
this.animal2 = ani2;
}
/**
Checks whether all animals in the zoo are normal size
@return string indicating whether check passed or failed
**/
public String healthCheck() {
if (animal1.isNormalSize() && animal2.isNormalSize()) {
return "Passed";
}
else {
return "Failed";
}
}
}
```
Things to prepare:
- Download the starter code (if relevant)
- Look at the `healthCheck` tests in the `AnimalTest` class: see if you can figure out how Java runs this function by tracking references to objects in memory
- List any questions that you have about the starter code