 Here are the first four elements in the periodic table. We can create a Java class to represent a chemical element. This class has no mutators, because once you've created an element, its characteristics don't change. Here's the code for the element class. It defines the properties, the constructor, and all of the accessors. Here's a program that calculates the average atomic weight for the first four elements. It creates four new element objects, adds their weights together, divides by four, and prints the result. Let's compile that and run it. And there's the answer. There's nothing wrong with this program, but if we had to do the average of the first 40 elements instead of just four, the code would become a lot longer and a lot more difficult to write and maintain. Just as we used arrays to group together similar values, such as an array of ints to hold test scores, or an array of double to hold an array of prices, we can create an array of element objects. We can say element array chemicals is a new element array of length four. And now we can put the objects into the array. We can say chemicals sub-zero is assigned hydrogen, chemicals of one becomes helium, chemicals two becomes lithium, and chemicals sub-three is assigned beryllium. Now we'll calculate the weight using a loop. The total starts off as zero, and for int i equals zero, i less than chemicals dot length. i plus plus will have total weight, plus and becomes chemicals sub i dot get weight. For the average, we'll divide the total by chemicals dot length. This gives us added flexibility. If we add more chemicals to the array, our code here doesn't have to change. Let's compile and run. This is some improvement, but not a great improvement over the original code. We can make our initialization a bit more compact by using braces to initialize. Instead of these five lines of code, we can say use braces to fill the array chemicals with hydrogen, helium, lithium, and beryllium. Let's compile it and run it. Again, it still works. We can also do the initialization directly without the need for our individual variables for hydrogen, helium, lithium, and beryllium. We'll put our declaration here. Element chemicals equals, and then in curly braces, we say that it's initialized with a new element for hydrogen, a new element for helium, a new element for lithium, and a new element for beryllium. And we no longer need our temporary variables. Let's compile and run. It still works. Finally, one more improvement. Because arrays of objects are arrays, we can use a for-each loop instead of a counting loop. We can say for each element, el, in the chemicals array, will take total weight plus and becomes that element's weight. Let's compile and run, and that works too. And that's what you need to know about creating and using arrays of objects.