Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will write two classes for program 7. Please submit all classes in one file.

ID: 3703778 • Letter: Y

Question

You will write two classes for program 7. Please submit all classes in one file. The name of the physical program file submitted xxxx_program7.

Assignment: A 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 a listing of all pets. You have to write a program to produce a report of animals and their owners from the data in the flat text file. Below is a description of the information on the text file:

? The first line on the file contains the number of animals on the file (numeric). It can be used to determine the size of the array. Your program should work for any number of Animals.

? The fields below repeat for each animal:

o Owner name (String)

o Birth year (numeric)

o Bill balance (numeric)

o Species (String)

Program requirements and grading:

From the information provided, write a solution that includes the following:

? An Animal class which includes:

o Instance variables (4 points)

o 2 Constructors (10 points)

o Accessor and mutator methods (16 points)

? Write a class xxxx_program7 which utilizes the following:

o An Array of Animal objects (5 points)

o A method which reads the input file provided and stores the objects in the array of Animals. (10 points)

o A method that formats and prints the output report. Please do not use a toString() method but rather call the getters of the Animal class to print the report. (7.5 points)

o The main method will call all the other methods which will: (7.5 points)

? Read the text file and store the objects in the array

? Format and print the report

? Test the program so that there are no errors using the input file provided, program7.txt. Note that the program will only be tested using the file posted on Blackboard. You should not submit another file. (10 points)

? Submit your program in one file, xxxx_program7, where xxxx is your Kean email id. (5 points)

program7.txt

Explanation / Answer

package animal;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;

class Animal {

   private String ownerName;
   private int birthYear;
   private double balance;
   private String species;
   public Animal() {
       super();
      
   }
   public Animal(String ownerName, int birthYear, double balance, String species) {
       super();
       this.ownerName = ownerName;
       this.birthYear = birthYear;
       this.balance = balance;
       this.species = species;
   }
   public String getOwnerName() {
       return ownerName;
   }
   public void setOwnerName(String ownerName) {
       this.ownerName = ownerName;
   }
   public int getBirthYear() {
       return birthYear;
   }
   public void setBirthYear(int birthYear) {
       this.birthYear = birthYear;
   }
   public double getBalance() {
       return balance;
   }
   public void setBalance(double balance) {
       this.balance = balance;
   }
   public String getSpecies() {
       return species;
   }
   public void setSpecies(String species) {
       this.species = species;
   }
  
  
  
}

public class Animal_Program7 {

   public static void main(String[] args) {
       Animal[] animalArray=null;
        final int num=0;
       try {
           File file = new File("program7.txt");
           FileReader fileReader = new FileReader(file);
           BufferedReader bufferedReader = new BufferedReader(fileReader);
           StringBuffer stringBuffer = new StringBuffer();
           String line;
           while ((line = bufferedReader.readLine()) != null) {
               stringBuffer.append(line);
               stringBuffer.append(" ");
           }
           fileReader.close();
           System.out.println("Contents of file:");
           String[] strObj=stringBuffer.toString().split(" ");
          
           int n=Integer.parseInt(strObj[0]);
           System.out.println(Arrays.toString(strObj));
          
           animalArray=new Animal[n];
          
           for(int i=1;i<animalArray.length+1;i++){
              
               Animal animal=new Animal();
              String[] str=strObj[i].trim().split(" ");
              System.out.println(Arrays.toString(str));
              animal.setOwnerName(str[0]);
              animal.setBirthYear(Integer.parseInt(str[1]));
              animal.setBalance(Double.parseDouble(str[2]));
              animal.setSpecies(str[3]);
             animalArray[i-1]=animal;        
          
           }
           System.out.println("Array size"+animalArray.length);
          
       int k=1;
           for(Animal animal:animalArray){
               System.out.println("Animal "+k);
               System.out.println(animal.getOwnerName());
               System.out.println(animal.getBirthYear());
               System.out.println(animal.getSpecies());
               System.out.println(animal.getBalance());
               System.out.println("================================");
               k++;
           }

          
       } catch (IOException e) {
           e.printStackTrace();
       }

   }
  
  
}


/* output:-

Contents of file:
[11, Hopper 2003 555 Kangaroo, Kitty-1 2009 44 Cat, Spotty 2005 333 Dog, Johnny 2008 111 Cat, Danny 2015 433 Dog, Striper 2011 432 Skunk, Edward 1995 630 Horse, Casper 1998 88 Snake, Bootsy 2005 987 Horse, Ryanne 2014 21 Fish, Jonny 2015 1500 Monkey]
[Hopper, 2003, 555, Kangaroo]
[Kitty-1, 2009, 44, Cat]
[Spotty, 2005, 333, Dog]
[Johnny, 2008, 111, Cat]
[Danny, 2015, 433, Dog]
[Striper, 2011, 432, Skunk]
[Edward, 1995, 630, Horse]
[Casper, 1998, 88, Snake]
[Bootsy, 2005, 987, Horse]
[Ryanne, 2014, 21, Fish]
[Jonny, 2015, 1500, Monkey]
Array size11
Animal 1
Hopper
2003
Kangaroo
555.0
================================
Animal 2
Kitty-1
2009
Cat
44.0
================================
Animal 3
Spotty
2005
Dog
333.0
================================
Animal 4
Johnny
2008
Cat
111.0
================================
Animal 5
Danny
2015
Dog
433.0
================================
Animal 6
Striper
2011
Skunk
432.0
================================
Animal 7
Edward
1995
Horse
630.0
================================
Animal 8
Casper
1998
Snake
88.0
================================
Animal 9
Bootsy
2005
Horse
987.0
================================
Animal 10
Ryanne
2014
Fish
21.0
================================
Animal 11
Jonny
2015
Monkey
1500.0
================================


*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote