Assignment #4


For this assignment you may complete problems #2 and #3 within the same class if you like.


Problem #1 (14 points)

Create a class called ‘Dog’. Have fields for: name (String), type of species (String), and age (int). Choose identifiers wisely. Create all the usual methods that are required for user-defined classes.  At this point, of course, the visibility of your 3 fields must all be private. Have a default constructor, and a constructor that allows you to initialize all 3 of the fields. Have a printInfo method.


Problem #2 (6 points)

In a test class, instantiate two Dog objects using the two different constructors. Also demonstrate use of at least two of your accessor and two of your mutator methods.

Bonus 3 points: Create an array of 100 Dog objects. Initialize each element of the array using the default constructor.


Problem #3 (20 points)

·         You will need the file oneToTen.txt which can be found on the class web page.

·         Prompt the user for a number between 1 and 10. When they pick a number, tell them how many times that number appears in the file oneToTen.txt.   As a test, if the user enters 8, you should find that it is present 54 times in the file.

·         Using a while or do-while loop, allow the user to repeat this search as many times as they like.




As usual, ZIP all of your source code files and submit to D2L.