Question: I need help for this project in a Java language. This is an extension to the class Dog example on the class. You may use

I need help for this project in a Java language. This is an extension to the class Dog example on the class. You may use the example as a starting point for this project. It is okay to copy code from any file posted on the class. Add a constructor to the Dog class that takes a file Scanner object as its only parameter. The file will consist of attributes of dogs. As read from the keyboard in the Dogs example Let the new constructor read three lines from the file, using the scanner object passed by the caller, to get the attributes of a single dog, and use those values to initialize a Dog object: Name Breed Age Remember that you will need to clear a blank line from the Scanner after reading the dog's age as an integer. Let the new constructor have the signature Dog(Scanner dogScanner) Modify the Dog class to keep track of how many Dog objects have been created since the program started. Add a static member function to return the number of Dogs in the system: public static int Get_Dog_Count(). Create a test driver called DogsFromFile. Accepts input from the keyboard for a file name. Creates a Scanner object for the file. Repeatedly invokes the new Dog constructor, passing the Scanner object as the only parameter value. Adds the resulting Dog object to an array. Upon reaching end of file, steps through the array of Dogs and outputs the attributes of each dog to the screen. Finally, invokes the new static member function of class Dog, Get_Dog_Count, to get the number of Dog objects that have been created and outputs the value to the screen. You may assume that there will be no more than 100 dogs in the file. If the file specified by the user does not exist, output an error message and let the user try again.

Here the start code.

public class Dog { // Instance variables private String name; private String breed; private int age; //----------------------------------------------------- // Constructor - sets up a dog object by initializing // the name, the breed, and the age. //----------------------------------------------------- public Dog(String newName, String newBreed, int newAge) { name = newName; breed = newBreed; age = newAge; } //-------------------------------------------------------------- // Method ageInPersonYears that takes no parameter. The method // should compute and return the age of the dog in person years // (seven times the dog's age). //-------------------------------------------------------------- public int ageInPersonYears() { int personAge = age*7; return personAge; } //------------------------------------------------------ // Returns a string representation of a dog. //------------------------------------------------------ public String toString() { return name + "\t"+ breed + "\t" + age + " age in person years:" + ageInPersonYears(); } } 

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!