Ramirez Albarran Omar escom ipn 6SCV2

Site hosted by Angelfire.com: Build your free website today!

Práctica 2

/*
* mascota.java
*
* Created on March 25, 2003, 6:57 PM
*/

/**
*
* @author omar
*/

import java.lang.*;
import java.io.*;
import java.util.*;
import java.math.*;

interface Mascotas{
public void mata();
}

interface Perros extends Mascotas{}
interface Gatos extends Mascotas{}
interface Roedores extends Mascotas{}

class Perro implements Perros{
public Perro(){System.out.print("\tPerro\n");}
public void mata(){System.out.println("muerto perro");};
}

class Doberman extends Perro{
public Doberman(){System.out.print("\tDoberman\n");}}

class Gato implements Gatos{
public Gato(){System.out.print("\tGato\n");}
public void mata(){System.out.println("muerto gato");};
}

class Ciames extends Gato{
public Ciames(){System.out.print("\tCiames\n");}}

class Roedor implements Roedores{
public Roedor(){System.out.print("\tRoedor\n");}
public void mata(){System.out.println("muerto roedor");};
}

class Hamster extends Roedor{
public Hamster(){System.out.print("\tHamster\n");}}


class Ex extends Exception{
Ex(String hola){super ("Hay problemas.... : "+ hola);}
}

class mascota{
static int r,i,ra,gatos, perros,roedor,dober,ciames,hams;
static Random s= new Random();

public static void matar(int r) throws Ex{
if(r==0){throw new Ex ("no mates los perros");}
else{ }
}

public static void main(String args[]){
Mascotas arreglo[] = new Mascotas[20];

System.out.println("\t\t + cotas\n\n\t");
System.out.print("\tDeme el numero de animales : ");
r=Getdat.getInt();

for(int m=0;m<r;m++){

ra=s.nextInt(6);
System.out.print(ra);

if (ra==0){ arreglo[i]=new Perro(); i++;perros++;}
else if (ra==1){ arreglo[i]=new Gato(); i++;gatos++;}
else if (ra==2){ arreglo[i]=new Roedor();i++;roedor++;}
else if (ra==3){ arreglo[i]=new Doberman();i++;dober++;
}
else if (ra==4){ arreglo[i]=new Ciames(); i++;ciames++;
}
else if (ra==5){ arreglo[i]=new Hamster(); i++;hams++;
}
}

System.out.print("\n\t Total de animales");

System.out.println("\n\n Total de perros : "+perros);
System.out.println(" Total de gatos : "+gatos);
System.out.println(" Total de roedores : "+roedor);
System.out.println(" Total de doberman : "+dober);
System.out.println(" Total de ciames : "+ciames);
System.out.println(" Total de hamster : "+hams);



for(int m=0;m<r;m++){

try{
mascota.matar(m);
}
catch(Ex e){
System.out.println(e.getMessage());
}

}
}



}