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 are 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 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
solution)
package com.anm.classes;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Test {
List mammals = new ArrayList();
List non_mammals = new ArrayList();
public void sort() {
Collections.sort(mammals);
Collections.sort(non_mammals);
}
public void output() {
System.out.println(\"the sorted birthbalance mammals are\");
for (Animal a : mammals) {
System.out.println(a.toStri.
The purpose of this project is to give students more exposure to obje.pdf
1. 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 are 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 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
solution)
package com.anm.classes;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
2. import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Test {
List mammals = new ArrayList();
List non_mammals = new ArrayList();
public void sort() {
Collections.sort(mammals);
Collections.sort(non_mammals);
}
public void output() {
System.out.println("the sorted birthbalance mammals are");
for (Animal a : mammals) {
System.out.println(a.toString());
}
System.out.println("the sorted birth balance non-mammals are");
for (Animal a : non_mammals) {
System.out.println(a.toString());
}
}
public static void main(String[] args) {
Test t = new Test();
String line = null;
try {
URL url = new URL("http://imc.kean.edu/CPS2231/program5.txt");
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(url.openStream()));
int count1 = 0;
while ((line = reader.readLine()) != null) {
String name = null;
int year = 0;
int birthBalance = 0;
String SpeciesName = null;
int type = 0;
String type1 = null;
3. String words[] = null;
count1++;
if (count1 == 1) {
System.out.println("the no of animals are :" + line);
} else {
// System.out.println(line);
words = line.split("s+");
name = words[0];
year = Integer.parseInt(words[1]);
birthBalance = Integer.parseInt(words[2]);
SpeciesName = words[3];
try {
type = Integer.parseInt(words[4]);
Animal a = new Mammal(name, year, birthBalance,
SpeciesName, type);
t.mammals.add(a);
// System.out.println(t.mammals.toString());
} catch (NumberFormatException e) {
type1 = words[4];
Animal a = new Non_Mammal(name, year, birthBalance,
SpeciesName, type1);
t.non_mammals.add(a);
// System.out.println(t.non_mammals.toString());
}
}
}
} catch (IOException e) {
System.out.println("unable to read the file");
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
System.out.println("file not found");
}
t.sort();
t.output();
}
4. }
output
the no of animals are :73
the sorted birthbalance mammals are
Mammal [mammal legs are :4 , name=kitty , year=2009 , birthBalance=44 ,
SpeciesName=Cat]
Mammal [mammal legs are :2 , name=Ray , year=2013 , birthBalance=50 ,
SpeciesName=Chicken]
Mammal [mammal legs are :4 , name=kitty2 , year=2009 , birthBalance=64 ,
SpeciesName=Cat]
Mammal [mammal legs are :4 , name=kitty3 , year=2009 , birthBalance=64 ,
SpeciesName=Cat]
Mammal [mammal legs are :4 , name=Johnny , year=2008 , birthBalance=111 ,
SpeciesName=Cat]
Mammal [mammal legs are :4 , name=Johnny2 , year=2008 , birthBalance=111 ,
SpeciesName=Cat]
Mammal [mammal legs are :4 , name=Johnny3 , year=2008 , birthBalance=111 ,
SpeciesName=Cat]
Mammal [mammal legs are :4 , name=William , year=2009 , birthBalance=113 ,
SpeciesName=Cat]
Mammal [mammal legs are :2 , name=Grant , year=2013 , birthBalance=150 ,
SpeciesName=Duck]
Mammal [mammal legs are :4 , name=William2 , year=2009 , birthBalance=213 ,
SpeciesName=Cat]
Mammal [mammal legs are :4 , name=William3 , year=2009 , birthBalance=213 ,
SpeciesName=Cat]
Mammal [mammal legs are :2 , name=Ray2 , year=2013 , birthBalance=250 ,
SpeciesName=Chicken]
Mammal [mammal legs are :2 , name=Ray3 , year=2013 , birthBalance=250 ,
SpeciesName=Chicken]
Mammal [mammal legs are :4 , name=John , year=2014 , birthBalance=300 ,
SpeciesName=Cat]
Mammal [mammal legs are :4 , name=John2 , year=2014 , birthBalance=320 ,
SpeciesName=Cat]
Mammal [mammal legs are :4 , name=John3 , year=2014 , birthBalance=320 ,
SpeciesName=Cat]
5. Mammal [mammal legs are :4 , name=Spot , year=2005 , birthBalance=333 ,
SpeciesName=Dog]
Mammal [mammal legs are :4 , name=Spot2 , year=2005 , birthBalance=333 ,
SpeciesName=Dog]
Mammal [mammal legs are :4 , name=Spot3 , year=2005 , birthBalance=333 ,
SpeciesName=Dog]
Mammal [mammal legs are :2 , name=Grant2 , year=2013 , birthBalance=350 ,
SpeciesName=Duck]
Mammal [mammal legs are :2 , name=Grant3 , year=2013 , birthBalance=350 ,
SpeciesName=Duck]
Mammal [mammal legs are :4 , name=Sam , year=2014 , birthBalance=400 ,
SpeciesName=Tiger]
Mammal [mammal legs are :4 , name=Sam2 , year=2014 , birthBalance=410 ,
SpeciesName=Tiger]
Mammal [mammal legs are :4 , name=Sam3 , year=2014 , birthBalance=410 ,
SpeciesName=Tiger]
Mammal [mammal legs are :4 , name=Striper , year=2011 , birthBalance=432 ,
SpeciesName=Sckunk]
Mammal [mammal legs are :4 , name=Dan , year=2015 , birthBalance=433 ,
SpeciesName=Dog]
Mammal [mammal legs are :4 , name=Dan2 , year=2015 , birthBalance=433 ,
SpeciesName=Dog]
Mammal [mammal legs are :4 , name=Dan3 , year=2015 , birthBalance=433 ,
SpeciesName=Dog]
Mammal [mammal legs are :4 , name=Boots2 , year=2005 , birthBalance=487 ,
SpeciesName=Horse]
Mammal [mammal legs are :4 , name=Boots3 , year=2005 , birthBalance=487 ,
SpeciesName=Horse]
Mammal [mammal legs are :4 , name=Mary , year=2013 , birthBalance=500 ,
SpeciesName=Dog]
Mammal [mammal legs are :4 , name=Mary2 , year=2013 , birthBalance=520 ,
SpeciesName=Dog]
Mammal [mammal legs are :4 , name=Mary3 , year=2013 , birthBalance=520 ,
SpeciesName=Dog]
Mammal [mammal legs are :2 , name=hopper , year=2003 , birthBalance=555 ,
SpeciesName=Kangaroo]
6. Mammal [mammal legs are :2 , name=Hopper2 , year=2003 , birthBalance=575 ,
SpeciesName=Kangaroo]
Mammal [mammal legs are :2 , name=Hopper3 , year=2003 , birthBalance=575 ,
SpeciesName=Kangaroo]
Mammal [mammal legs are :4 , name=Green2 , year=2011 , birthBalance=600 ,
SpeciesName=Horse]
Mammal [mammal legs are :4 , name=Green3 , year=2011 , birthBalance=600 ,
SpeciesName=Horse]
Mammal [mammal legs are :4 , name=Edward , year=1995 , birthBalance=630 ,
SpeciesName=Horse]
Mammal [mammal legs are :4 , name=Edward2 , year=1995 , birthBalance=630 ,
SpeciesName=Horse]
Mammal [mammal legs are :4 , name=Edward3 , year=1995 , birthBalance=630 ,
SpeciesName=Horse]
Mammal [mammal legs are :4 , name=Striper2 , year=2011 , birthBalance=732 ,
SpeciesName=Sckunk]
Mammal [mammal legs are :4 , name=Striper3 , year=2011 , birthBalance=732 ,
SpeciesName=Sckunk]
Mammal [mammal legs are :4 , name=Green , year=2011 , birthBalance=800 ,
SpeciesName=Horse]
Mammal [mammal legs are :4 , name=Sarah , year=2011 , birthBalance=900 ,
SpeciesName=Horse]
Mammal [mammal legs are :4 , name=Sarah2 , year=2011 , birthBalance=950 ,
SpeciesName=Horse]
Mammal [mammal legs are :4 , name=Sarah3 , year=2011 , birthBalance=950 ,
SpeciesName=Horse]
Mammal [mammal legs are :4 , name=Boots , year=2005 , birthBalance=987 ,
SpeciesName=Horse]
Mammal [mammal legs are :2 , name=Austin , year=2015 , birthBalance=1500 ,
SpeciesName=Monkey]
Mammal [mammal legs are :2 , name=Austin2 , year=2015 , birthBalance=2500 ,
SpeciesName=Monkey]
Mammal [mammal legs are :2 , name=Austin3 , year=2015 , birthBalance=2530 ,
SpeciesName=Monkey]
the sorted birth balance non-mammals are
Non_Mammal [type=Cold-Blooded , name=Duke , year=2014 , birthBalance=10 ,