CS46A Fall 19

10A

In this problem you will write several static methods to work with arrays and ArrayLists. Remember that a static method does not work on the instance variables of the class. All the data needed is provided in the parameters. Call the class StaticLib. Notice how the methods are invoked in StaticLibTester.

StaticLib is a utility class. It should not have instance variables or a constructor. The purpose of a class like this is to house some useful methods

Notice that there are two methods called max and two methods called getCount. These are examples of overloading - methods with the same name but different number and type of parameters. The compiler tells them apart because in each case, one takes an array and one an ArrayList as a parameter.

When using the enhanced for loop, the implementation of the pairs of methods will be very similar. The exact same loop works for both

Provide Javadoc. Look at the documentation produced for StaticLib. The Javadoc utility works on static methods, too.

For the draft, implement the first max method

10A draft:
10A final:

10B

In this problem you will use the design pattern for maintaining state. Write a Wildebeest class. A Wildebeest has 4 states. You will define and use these static constants to represent the states.

In your code you can not assume what the value is for any of the constants, but you can assume that the values are consecutive integers. That is, VERY_HUNGRY will be 1 greater than HUNGRY, etc.

Wildebeests migrate across the Serengeti Plain in Tanzania.

wildebeest

(image from Wikipedea)

A Wildebeest runs across the plain and as it runs, it becomes more hungry. If it is NOT_HUNGRY, it becomes SOMEWHAT_HUNGRY. If it is SOMEWHAT_HUNGRY, it becomes HUNGRY and so on. When the Wildebeest sees food, if it is in any of the "hungry states", it will eat and become one level less hungry. If the Wildebeest is VERY_HUNGRY when it sees food, it will eat and become HUNGRY. The next time it sees food, it will eat again and become SOMEWHAT_HUNGRY. If it is NOT_HUNGRY, it does not eat and its state does not change.

The Wildebeest can not be less than NOT_HUNGRY or more than VERY_HUNGRY.

The constructor takes no parameters. A Wildebeest is very hungry when it is creates so the constructor must initialize the state to VERY_HUNGRY. (Do not set it to the literal 4)

Provide methods:

Provide Javadoc

For the draft, provide the static constants, implement the constructor, and the getState() method. Implement the other methods as stubs. Provide Javadoc

10B draft:
10B final:

10C

Now we are going to use the design pattern for collecting objects. We are going to model a GardenStore with plants. A GardenStore uses an ArrayList to keep track of Plant objects. You will write both a GardenStore class and a Plant class.

Plant has a name and a price. Provide a constructor that takes name and price, in that order. Provide getters and setters for the instance variables. This is the design pattern for managing properties of objects.

GardenStore has a constructor that takes no parameters. Remember it must initialize the instance variable

It has methods

Provide Javadoc for both classes.

For the draft: implement the Plant class

Note: The Plant class will not change in the final, but you will need to submit it again so that GardenStore can find it.

10C draft:
10C final: