Inheritance. The text file. Working class dogs not added yet Butch#2#false April#1#true Morgan#4#false Ratty#9#false Tut#2#true =========================================================== The UI class that will call the methods in the manager class /* * Super class: Dogs. Subclass: Working dogs * Read in from a text file */ package inheritance; public class DogsUI { public static void main(String[] args) { DogManager dm = new DogManager(); String text = dm.displayAll(); System.out.println("Hello Dogs"); System.out.println(text); } } =============================================================== The Manager class where we will place all our methods. The constructor method will read in the text file and instantiate an array of dog objects. /* * Dog Manager with methods to create object arrays */ package inheritance; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import java.util.logging.Level; import java.util.logging.Logger; public class DogManager { // global variables including arrays private Dogs[] dogArray = new Dogs[20]; private int size = 0; DogManager() { try { Scanner scFile = new Scanner(new File("dogs.txt")); while(scFile.hasNext()) { String line = scFile.nextLine(); Scanner scLine = new Scanner(line).useDelimiter("#"); String name = scLine.next(); String ageSt = scLine.next(); int age = Integer.parseInt(ageSt); String pedigreeSt = scLine.next(); boolean pedigree = Boolean.parseBoolean(pedigreeSt); dogArray[size] = new Dogs (name, age, pedigree); size = size + 1; } // end while System.out.println("File Found"); } catch (FileNotFoundException ex) { Logger.getLogger(DogManager.class.getName()).log(Level.SEVERE, null, ex); } } public String displayAll() { String s = ""; for(int i = 0; i < size; i++) { s = s + dogArray[i] + "\n"; } // end for return s; } } ============================================================================== The Dog class - the super class. The dog class constructor must match the working dog constructor. /* * Super class: Dogs. Subclass: Working dogs */ package inheritance; public class Dogs { String name = null; int age = 0; boolean pedigree = false; Dogs(String n, int a, boolean p) { name = n; age = a; pedigree = p; } public String toString() { return name + "\t" + age + "\t" + pedigree; } } =============================================================================== /* * Extends the dog class */ package inheritance; public class WorkingDog extends Dogs{ // Working dog has an additional field String trainer = "Nil"; // Sub-class constructor uses the super-class constructor, just adding the // extra field WorkingDog(String n, int a, boolean p, String t) { super(n,a,p); trainer = t; } // end constructor public String toString() { // returns Dog toString with the extra field return super.toString() + "\t" + trainer; } } ================================================================================ OUTPUT run: File Found Hello Dogs Butch 2 false April 1 true Morgan 4 false Ratty 9 false Tut 2 true =================================================================================