Instructions: This is an ungraded fill-in-the-blank exercise. Each question consists of a sentence with one or two words left out. A button represents the missing word(s). For each question, think of the word or phrase that should fill each blank, then click on the buttons to see if you are correct. No grade is calculated for this exercise.
Often students get stuck in writing a program because there seem to be too many ways to do something and it is not clear which one is correct. This exercise several ways in which a program could be written to accomplish the same task. The programs are increasingly complicated, and probably increasingly bad program designs for the problem as stated.
In this program one Vesta object is created, who's speak() method is invoked size times. If all that you wanted to do was to write the phrase six times, the first version of the program is probably better than this version.
This version of the program is less efficient than the previous program because this version creates six objects all of which do the same thing, and each of which immediately becomes garbage after it is used. Ordinarilly this is regarded as poor programming.
The new operator is used to create each object and each newly created object's speak() method is invoked. In spite of its sophistication, this version of the program is about as impractical as the previous version.
This version has the advantage that only one object is created, and has the further advantage that main() is now a very simple program. If main() is expected to be become longer as more and more things are added to it, the Vesta object might be sensible. But the the simple task as stated, the first program is still the best.
Again, whether the Vesta class is sensible depends on the task. If the task is complicated, and the above program is just a small step toward a complete solution, then maybe the Vesta class is a good design.
This version of the Vesta class is more flexible than the previous version. It is probably better since it can be used for more situations than the previous.
This version seem more logical, as well as being more versatile. The number of times a message should be repeated should be a characteristic of the request, not an inherent characteristic of the object.
Notice carefully the difference between a constructor and a method: a constructor initializes data in a object when the object is being created. Every use of a constructor creates a new object. A method is part of an existing object. It can change the data of its object. Because the data in Vesta objects can be changed, they are NOT immutable.