import java.util.InputMismatchException; import java.util.Scanner; /** * Simple implementation of a class to describe a cat * @author gtowell * Created: Feb 2021 */ public class Cat extends Pet { // the breed private String breed; // hair length -- not used private double hairLength; /** * Constructor. Just copies the values into instance vars * @param name the name * @param id the id * @param breed the breed */ public Cat(String name, String id, String breed) { this.name = name; this.iD = id; this.breed = breed; } /** * Constructor. Gets values from keyboard * @throws InputMismatchException */ public Cat() throws InputMismatchException { Scanner scanner = new Scanner(System.in); System.out.print("Enter name: "); name = scanner.next(); System.out.print("Enter Id:"); iD = "" + scanner.nextInt(); System.out.print("Enter breed: "); breed = scanner.next(); } /** * The sound a cat makes */ @Override public String sound() { return "meow"; } @Override public String toString() { return "My name is " + name + " breed " + breed + " and I say " + sound(); } public static void main(String[] args) { System.out.println(new Cat("calypso", "112234", "siberian")); /** try { Cat c = new Cat(); System.out.println(c); } catch (InputMismatchException ime) { System.err.println("No Cat :-("); } **/ } }