Txerrinko

PrincipalLoro

Mar 18th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.05 KB | None | 0 0
  1. package Ejercicio4;
  2.  
  3. public class Loro  extends Ave{
  4.    
  5.     private char region;
  6.    
  7.     private String color;
  8.    
  9.     Loro(char psexo, int pedad, char pregion, String pcolor, String Pnombres){
  10.        
  11.         super(psexo,pedad,Pnombres);
  12.        
  13.         region=pregion;
  14.        
  15.         color=pcolor;
  16.        
  17.     }
  18.    
  19.    
  20.     void deDondeEres(){
  21.        
  22.         if(region=='N')
  23.         {
  24.             System.out.println("Soy del Norte ");
  25.         }
  26.         else if(region=='S')
  27.         {
  28.             System.out.println("Soy del Sur");
  29.         }
  30.         else if(region=='E')
  31.         {
  32.             System.out.println("Soy del Este");
  33.         }
  34.         else
  35.            
  36.             System.out.println("Soy del Oeste");
  37.    
  38.     }
  39.     /*
  40.     public char getregion(){
  41.        
  42.         return region;
  43.     }*/
  44.    
  45.     void setregion(char r){
  46.        
  47.         region=r;
  48.         }
  49.    
  50.     public String getcolor(){
  51.        
  52.         return color;
  53.     }
  54.  
  55.    
  56.     void cantar(){
  57.        
  58.        
  59.         System.out.println("Mi nombre es " + getnombres() + ", Pio-pio Loro bonito");
  60.        
  61.     }
  62.    
  63.    
  64. }
  65.    
  66. package Ejercicio4;
  67.  
  68. public class Ave {
  69.  
  70.    
  71.     private char sexo;
  72.     private int edad;
  73.     protected static  int contaves=0;
  74.     private  String nombres;
  75.    
  76.     Ave(char psexo,int pedad, String Pnombres){
  77.        
  78.         edad=pedad;
  79.         sexo=psexo;
  80.         contaves++;
  81.         nombres=Pnombres;
  82.     }
  83.    
  84.     private void contAves(){
  85.        
  86.         System.out.println("El numero de Aves es " + contaves);
  87.        
  88.     }
  89.    
  90.     protected void quienSoy(){
  91.        
  92.         System.out.println("El sexo del Ave es " + sexo);
  93.        
  94.         System.out.println("La edad del Ave es " + edad);
  95.        
  96.     }
  97.    
  98.    
  99.     public int getcontaves(){
  100.        
  101.         return contaves;
  102.     }
  103.    
  104.     void cantar(){
  105.        
  106.         System.out.println("Mi nombre es XXX, Pio-pio soy un Ave");
  107.        
  108.     }
  109.    
  110.         public String getnombres(){
  111.            
  112.             return nombres;
  113.         }
  114.        
  115.  
  116. }
  117.  
  118.     package Ejercicio4;
  119.  
  120. public class DatosPersonales {
  121.  
  122.     private String nom_ave;
  123.     private String nom_duenio;
  124.    
  125.        
  126.         public DatosPersonales(String Pnom_ave,String Pnom_duenio){
  127.            
  128.             nom_duenio=Pnom_duenio;
  129.             nom_ave=Pnom_ave;
  130.            
  131.        
  132.         }
  133.    
  134.         public String getnom_ave(){
  135.            
  136.             return nom_ave;
  137.         }
  138.        
  139.         public void setnom_ave(String n){
  140.            
  141.             nom_ave= n;
  142.            
  143.         }
  144.        
  145.         public String getnom_duenio(){
  146.            
  147.             return nom_duenio;
  148.         }
  149.        
  150.         public void setnom_duenio(String nom){
  151.            
  152.             nom_duenio=nom;
  153.         }
  154. }
  155.  
  156.    
  157.    
  158.     package Ejercicio4;
  159.  
  160. import ejercicio3ave.DatosPersonales;
  161.  
  162. public class PrincipalLoro {
  163.  
  164.    
  165.     static final int N = 3;
  166.    
  167.     public static void main(String[] args) {
  168.         // TODO Auto-generated method stub
  169.      
  170.  
  171.         Loro[] lista1 =
  172.             {new Loro( 'M' ,40 , 'S' ,"verde","pere" ),
  173.             new Loro ('H', 22, 'N', "azul","pero"),
  174.             new Loro ('M',19, 'O', "morado","peru")};
  175.         Loro[] lista2 =
  176.             {new Loro( 'H' ,42 , 'S' ,"ROJO","koke" ),
  177.             new Loro ('H', 22, 'N', "yellow","squirtle"),
  178.             new Loro ('M',21, 'O', "purple","pera")};
  179.         Loro[] lista3 = new Loro[N*2];
  180.        
  181.        
  182.         int j=0;
  183.         for(int i=0; i< lista3.length;i=i+2){
  184.            
  185.             lista3[i]=lista1[j];
  186.             lista3[i+1]=lista2[j];
  187.             j++;
  188.            
  189.         }
  190.        
  191.         for ( int i=0; i<lista3.length;i++){
  192.          
  193.             lista3[i].cantar();
  194.            
  195.         }
  196.        
  197.        
  198.         for  ( int i=0;i<lista3.length;i++){
  199.            
  200.             lista3[i].getnombres().substring(0,3);
  201.            
  202.            
  203.         }
  204.        
  205.        
  206.     }
  207.  
  208.    
  209.    
  210. }
Advertisement
Add Comment
Please, Sign In to add comment