What to do

Create a project consisting of four classes. These four classes will be ProgThree.java, Animal.java, Pet.java, and ZooAnimal.java. You must have these four classes and they must work as it is described in these specifications. You may add other classes and methods if you consider them necessary.

This assignment requires you to implement at least four classes. The first class, Animal, stores basic data about an animal. The second class Pet, stores additional data about an animal which is a pet. The third class ZooAnimal, stores additional data about an animal which is kept in a zoo. The fourth class ProgThree has a main method which reads data about animals, pets and zoo animals and creates a report about animals, pets and zoo animals.

Your program must be developed following the guidelines previously discussed in class. These guidelines include appropriate variable names, use of comments to describe the purpose of the program and the purpose of each method, and proper use of indentation of all program statements.

Animal.java technical details:

One Constructor

Constructor #1. It will takeall the parameters as listed:
int animalID
String animalType
double weight

Instance variables for the Animal class

int animalID.
String animalType.
double weight.

Method which must be part of the Animal class:

A toString() method which displays information about an animal in the following format:

ID: 1015 Type: Monkey Weight: 38.6

Pet.java technical details:

One Constructor - the first three parameters are passed to the Animal class constructor in the first line of the Pet constructor by using the super reference.

Constructor. It will take all the parameters as listed:
int animalID.
String animalType.
double weight.
String name;
String owner;

Instance variables for the Pet class

String name;
String owner;

Method which must be part of the Pet class:

A toString() method which displays information about an animal in the following format:

ID: 5089 Type: Fish Weight: 0.2
Name: Sally Owner: Henry Santos

Note: The toString() Method gets the first line of output from the Animal class toString method.

Animal is a parent class of the Pet class.

ZooAnimal.java technical details:

One Constructor - the first three parameters are passed to the Animal class constructor in the first line of the ZooAnimal constructor by using the super reference.

Constructor #1. It will take all the parameters as listed:
int animalID.
String animalType.
double weight.
int cageNumber.
String trainer.

Instance variables for the ZooAnimal class

int cageNumber.
String trainer.

Method which must be part of the ZooAnimal class:

A toString() method which displays information about an animal in the following format:

ID: 8850 Type: Fish Weight: 0.2
Cage: 103 Trainer: Suzie Tran

Note: The toString() Method gets the first line of output from the Animal class toString method.

Animal is a parent class of the ZooAnimal class.

ProgThree.java Specifications:

ProgThree should read information about animals, pets and zoo animals. Initial data about pets is available in a text file named animal.txt. The program should read one line of input from the text file and process it independently. The program should continue until all lines of the input file have been processed.

The input file will contain a single line of data about each animal, pet or zoo animal. There are several lines in the input file and the animals, pets and zoo animals are mixed together. A input line will either contain three or five pieces of data. An input line with three pieces of data is an animal, and those three pieces of data will be animal id, type and weight, in order. Pets and zoo animals have the same first three pieces of data and then two additional pieces of data. If the animal id is between 3,000 and 7,999 the input record is about a pet and the last two pieces of data are the pet's name and the owners name, both strings. If the animal id is between 8,000 and 9,999 the input record is about a zoo animal and the last two pieces of data are the cage number, an integer and the trainers name, a string.

The rules for valid input records, follow:

The first piece of data is animalID. It must be a four digit positive integer. Records whose ID numbers are between 3,000 and 7,999 should contain data about a "pet". Records whose ID numbers are between 8,000 and 9,999 should contain data about a zoo animal. Records whose ID numbers are between 1,000 and 2,999 should contain data about an animal. Records whose ID numbers are less than 1,000 or greater than 9,999 should be considered to be invalid records.

animalType must be a string of at least three characters.

weight must be a valid positive real number.

For "Pet" objects, name and owner each must be strings of at least three characters.

For "Zoo Animal" objects, cageNumber must be a positive integer and trainer must be a string of at least three characters.

You may assume that input records will contain data of the data types needed by the program. For example, for input records of animals the record will contain an int, String and double in that order. You may not assume, however, that the input records will contain valid data. For example, the weight will be a real number (data type matches) but it may be negative making the input record invalid. In another input record, the animalType is a string but only contains two characters, making it an invalid record.

After reading in the data, determine if the data contained in the record is valid. If so, construct the appropriate type of object and write the object's data to the output file, "animalout.txt". If not, ignore the input record and proceed to the next record. When all of the animals have been processed, write to the output the total number of each, animals, pets and zoo animals written to the output file. Close the output file and end the program. You will need to use skills learned in modules two through seven and ten to complete this program.

Input value is completely valid.

No user interface.

Extra Credit- program completed as instructed and then with EXCEPTION HANDLING.

Questions

1. Assume that you have an array declared as: double[] scores = new double[50]; and that every compartment of the array contains a real number between 0.0 and 100.0 inclusive.

a. A passing score is 70.0 or higher and a failing score is less than 70.0. Write a code segment to calculate the number of passing scores and the number of failing scores in the array.

b. Write a code segment which calculates and displays:

1. the average of the scores in the array

2.Assume that an arrays has been defined:

int[] par = new int[18];
int[] strokes = new int[18];

Assume that every compartment of the arrays contains an appropriate integer value representing the par value and the number of strokes made by a golfer on each hole of an eighteen hole golf course.

a.Write a code segment that calculates and displays the number of holes upon which the golfer made an eagle. To make an eagle, the number of strokes made by the golfer must be two fewer than the par value for the hole.

b.Write a code segment to display the hole numbers for all holes on which the golfer missed par. To miss par, the number of strokes on the hole must be greater than the par value for the hole.

3. Write a code segment which accepts the price of a tour. A tour is priced between 29.95 and 249.99. Your code segment should handle any user input nicely and should continue to repeat until a valid price is entered.

Example:

The user enters: 15.
You ask again
The user enters: bb
You ask again
The user enters: 250
You ask again
The user enters: 75.12
Exit

4. A ticket to a Waikiki show must store, Show Date and Time (a String), Seat Information (a String), and Price (a double). A VIP ticket to the same show includes dinner and must also store Meal Choice (a String).

Code the class heading, variable declarations and constructors for the "Ticket" and VIPTicket objects. VIPTicket is a subclass of the Ticket class and inherits all of its instance data variables.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.