/*** This reference program is provided by @jiuzhang.com* Copyright is reserved. Please indicate the source for forwarding*//** * Your object will be instantiated and called as such: * ToyFactory tf = new ToyFactory(); * Toy toy = tf.getToy(type); * toy.talk(); */interfaceToy {voidtalk();}classDogimplementsToy {// Write your code here @Overridepublicvoidtalk() {System.out.println("Wow"); }}classCatimplementsToy {// Write your code here @Overridepublicvoidtalk() {System.out.println("Meow"); }}publicclassToyFactory { /** * @param type a string * @return Get object of the type */publicToygetToy(String type) {// Write your code hereif (type ==null) {returnnull; } if (type.equalsIgnoreCase("Dog")) {returnnewDog(); } elseif(type.equalsIgnoreCase("Cat")) {returnnewCat(); }returnnull; }}