Question: Update the class with a constructor. In the constructor instantiate an ArrayList and assign it to the field. Add an application method. In main, instantiate

Update the class with a constructor. In the constructor instantiate an ArrayList and assign it to the field. Add an application method. In main, instantiate the class and call the add and print methods for the class. Notice that the print method uses the for-each loop, the "alternate" version of the for loop.

/** * This is the starting point code for Lab: Reindeer. */ public class Reindeer { // The reindeer private java.util.ArrayList reindeer; /** * Constructor, which you will write */ /** * Add the names of the reindeer to the collection. */ public void addReindeer() { reindeer.add("Dasher"); reindeer.add("Dancer"); reindeer.add("Prancer"); reindeer.add("Vixen"); reindeer.add("Comet"); reindeer.add("Cupid"); reindeer.add("Dunder"); reindeer.add("Blixem"); } /** * A simple method to print out the contents of * the collection. */ public void print() { for(Object o : reindeer) { System.out.print(o + " "); } System.out.println(); } /** * The application method, which you will write * @param args Command-line arguments */ }

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 Databases Questions!