Practice Programs
Practice Programs can generally be solved with a short program that directly applies the programming principles presented in this chapter.
Modify the definition of the class
Speciesin Listing 5.19 of Chapter 5 by removing the methodsetSpeciesand adding the following methods:Five constructors: one for each instance variable, one with three parameters for the three instance variables, and a default constructor. Be sure that each constructor sets all of the instance variables.
Four methods named
setthat can reset values: one is the same as the methodsetSpeciesin Listing 5.16, and the other three each reset one of the instance variables.
Then write a test program to test all the methods you have added. Finally, repeat Practice ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access