请按照Main类及输出案例
1. 编写抽象类Pet,包含构造方法, 抽象方法eat和setNameAge及成员变量:name, age;
2. 编写Dog类(Pet类的子类)。
3. 编写AgeException异常类,当年龄不大于零,抛出该类异常(Dog类中的setNameAge方法中抛异常, 输出:AgeException: age cannot be this.age)。
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner r = new Scanner(System.in);
int count;
try
{
count = r.nextInt();
Pet petList[] = new Pet[count];
for(int i=0;i<count;i++)
{
String name;
int age;
petList[i] = new Dog();
name = r.next();
age = r.nextInt();
petList[i].setNameAge(name, age);
petList[i].eat();
}
}
catch(AgeException e)
{
System.out.println(e);
}
catch(InputMismatchException e)
{
System.out.println(e+ ": count or age must be an integer");
}
catch(Exception e)
{
System.out.println(e+": othe