The purpose of this project is to give students more exposur

The purpose of this project is to give students more exposure to object oriented design and programming using classes and polymorphism in a realistic application that involves arrays of objects and sorting arrays containing objects. A large veterinarian services many pets and their owners. As new pets arc added to the population of pets being serviced, their information is entered into a flat text file. Each month the vet requests and updates listing of all pets sorted by their \"outstanding bill balance\". You are to write a program which will produce a report of animals and their owners sorted by their outstanding balances from the data in the flat text file. Program requirements and grading: A class named Animal with the following details and two subclasses Mammal and nonMammal Name (owner) a character string birth year numeric bill balance numeric species a character string Special specie feature: Mammal has legs or nonMammal has blood type (an animal cannot have both features) Constructor, Accessor and mutator method(s) of all classes An array of Animal objects Read an input text file from http://imc.kyan.cdu/CPS223l/nrogram5.txt with the ordering as above, one grouping for each animal will be provided. Also, the first item in the file is the number of animals. You should have I/O exception handling and display a message \"File cannot be found!\" if the URL is incorrect. One method for inputting each Animal object. One method for producing an output report - formatting is one Animal per line and at most 40 Animals per page. One method for sorting the array of Animals. One \"simple main\" method that: 1) calls for all input, 2) calls a sort method, and 3) calls for the report of the sorted list. Record your planning time, coding time, testing time and bug fixing time. Put these information in the comments at the top of the program. Please have short description in the comments before each method. Design thoughts: The use of methods and subclasses is very beneficial as programs become larger and their logic becomes more difficult. In fact, different industries/companies have their own software development requirements (standards) to improve readability, testability, maintainability and overall design. It is up to you to logically dissect the problem and determine the subclasses and methods you will be using in your design. I suggest that you use the Animal class as a super class and create new subclasses.

Solution

package arraylist.program;
import java.util.*;
import java.util.Scanner;
public class ArrayListProgram

{

public static void main(String[] args) {
      
// enables keyboard input
Scanner input = new Scanner(System.in)

//this creates the Array!
ArrayList<String> animalArray = new ArrayList<String>();

// Adding items to arrayList
animalArray.add(\"Zebra\");
animalArray.add(\"Lion\");
animalArray.add(\"Fish\");

// Display the contents of the array list
System.out.println(\"The array contains the following animals: \ \" + animalArray);
       
// Checking if array list is empty
boolean check = animalArray.isEmpty();
System.out.println(\"\ Verifying if the animal list is empty: \" + check);
       
System.out.println(\"\ Please enter the name of the animal \" + \"you want to retrieve: \");
  
String[] animals = new String[3];

// add elements to the array
animals[0] = \"Zebra\";
animals[1] = \"Lion\";
animals[2] = \"Fish\";
           
// String[] animal;
// declare a string array with no initial size
String useranswer;
useranswer = input.next();
  
// 1st way: loop using index and size list
System.out.println(\"\ Retrieving animal information!\");
               
if (animals[0].equals(useranswer) )

{
               String[] animals2 = {\"White & Black, Vetebrate, Non-Swim\"};
            // declare string array and initialize with values in one step
               
                int size = animals2.length;
              System.out.println(\"The size of array is: \" + size);
               for (int i = 0; i < size; i++)

{
                    System.out.println(\"\ Index[\" + i + \"] = \" + animals2[i]);
                    // iterate all the elements of the array    
}
            if( animals[1].equals(useranswer) )

{
               String[] animals3 = {\"Orange,Vetebrate, Non-Swim\"};
            // declare string array and initialize with values in one step
               
               int size = animals3.length;
               System.out.println(\"The size of array is: \" + size);
                  for (int i = 1; i < size; i++)

{
                    System.out.println(\"\ Index[\" + i + \"] = \" + animals3[i]);
                    // iterate all the elements of the array
}   
}
}

}
}

 The purpose of this project is to give students more exposure to object oriented design and programming using classes and polymorphism in a realistic applicati
 The purpose of this project is to give students more exposure to object oriented design and programming using classes and polymorphism in a realistic applicati

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site