Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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, 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) Use try/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.

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;

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

mypets.txt:

Fido poodle 3 17432 true Buster pug 6 43254 true Sally siamese no 39587 false Gina bulldog 5 3857 true Zelda shepherd 4 45827 true Thor shepherd true 48675 false Gidget pug 3 88954 true

This is Java.

Step by Step Solution

3.34 Rating (148 Votes )

There are 3 Steps involved in it

Step: 1

Short Summary Provided the source code and sample output as per the requirements Source Code Animaljava Animal class public class Animal instance variables private String name private String breed pri... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Marketing management

Authors: Philip Kotler, Kevin Lane Keller

14th Edition

9780273753360, 132102927, 273753363, 978-0132102926

More Books

Students also viewed these Marketing questions

Question

Describe and sketch the form of three-phase AC power.

Answered: 1 week ago

Question

Define belongingness, competence, and autonomy.

Answered: 1 week ago

Question

What have been the keys to Nokias global strength?

Answered: 1 week ago