For this assignment you will create an Animal class, with attributes for name, breed, and age.Then you will create one subclass for dog, that inherits the properties for Animal with unique...

1 answer below »

For this assignment you will create an Animal class, with attributes for name, breed, and age.Then you will create one subclass for dog, that inherits the properties for Animal with unique attributes.You will read data in from a file and create an arraylist of dog objects.Once you have read all the file inputs, you will display the dog objects to the user and write a corrected list (which removes corrupted data sets). We will be using a text file as input for this assignment.As you read in the data, you will verify the format.For data which has an error you will throw an exception, generate a message to the user, skip that data set, and continue the program execution.You must demonstrate use of a try/catch block.You will need to submit your java class files, an execution screenshot showing the exception message was thrown and the display of the dog information.The requirements for this assignment are specified in more detail below;


1)Create an Animal class with attributes for name, breed, and age.


2) Create a subclass for dog.Dog attributes should be AKC number, vaccinated (true/false).


3) Use the Java FileNotFoundException to provide a message to the user if the file is not available to be opened


4) Input data for objects from a provided text file (mypet.txt attached below)


5) Usetry/catch block to verify if the input received is in the correct format.If not, then skip that data (you need to skip all the fields associated with the corrupted object in order to start at the begining of the next object data) and send a message to the user to let them know there was a corrupted data field.


6) If the data is good, then create a dog object, initialize it with the data from the file (use an overloaded constructor) and store it in an arraylist.


7) Once all the data is brought in from the file, then display out the contents of the arraylist for the user (a simple list for each object is fine, it should look similar to the resulting text file) and write the objects to a new text file that will have only accurate data.Note that you will be able to use an overloaded toString to display objects, however, for objects written out to a text file you must use the dot operator (or getter if you encapsulate) to access each field in order to get a readable text output. Also, you must separate each data field with a space delimiter so that it is in a format that can be read in by your program.Hint:PWriter.write(dogs.get(i).name+" ");


Note that Boolean values will not write out to the file as text, so if you use Boolean for the vaccine attribute you will need to use an if statement to translate from Boolean to a string;


Hint:if(dogs.get(i).vaccine==true){


PWriter.write("true "); }


else{


PWriter.write("false ");


}










The following shows the user display from my program solution;


One entry was skipped due to a format error.


One entry was skipped due to a format error.


Fido poodle 3 17432 true


Buster pug 6 43254 true


Gina bulldog 5 3857 true


Zelda shepherd 4 45827 true


Gidget pug 3 88954 true

Answered Same DaySep 29, 2021

Answer To: For this assignment you will create an Animal class, with attributes for name, breed, and age.Then...

Aditya answered on Sep 30 2021
125 Votes
public class Animal {
    private String name;
    private String breed;
    private int age;
    
    
    publ
ic Animal() {
        
    }
    public Animal(String name, String breed, int age) {
        this.name = name;
        this.breed = breed;
        this.age = age;
    }
    public String getName() {
        return name;
    }
    public...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here