RE:polimorfismo, herencia y sobrecarga de funcione
public abstract class ClaseSuma{
public abstract int suma(byte a,byte b);
public abstract int suma(short a, short b);
public abstract long suma (int a,int b);
public abstract float suma(long a, long b);
}
public interface IResta{
public int resta(byte a,byte b);
public int resta(short a,short b);
public long resta(int a,int b);
public float resta(long a,long b);
}
public class OperacionesByte extends ClaseSuma implements IResta{
public int suma(byte a,byte b){
return a+b;
}
public int suma(short a, short b){}
public long suma (int a,int b){}
public float suma(long a, long b){}
public int resta(byte a,byte b){
return a-b;
}
public int resta(short a,short b){}
public long resta(int a,int b){}
public float resta(long a,long b){}
}
public class OperacionesShort extends ClaseSuma implements IResta{
public int suma(byte a,byte b){}
public int suma(short a, short b){
return a+b;
}
public long suma (int a,int b){}
public float suma(long a, long b){}
public int resta(byte a,byte b){
return a-b;
}
public int resta(short a,short b){}
public long resta(int a,int b){}
public float resta(long a,long b){}
}
public class OperacionesInt extends ClaseSuma implements IResta{
public int suma(byte a,byte b){}
public int suma(short a, short b){}
public long suma (int a,int b){return a+b;}
public float suma(long a, long b){}
public int resta(byte a,byte b){ }
public int resta(short a,short b){}
public long resta(int a,int b){return a-b;}
public float resta(long a,long b){}
}
public class OperacionesLong extends ClaseSuma implements IResta{
public int suma(byte a,byte b){}
public int suma(short a, short b){}
public long suma (int a,int b){}
public float suma(long a, long b){return a+b;}
public int resta(byte a,byte b){ }
public int resta(short a,short b){}
public long resta(int a,int b){}
public float resta(long a,long b){return a-b;}
}
public class Operaciones{
public Operaciones(String[] valorers,char operador) throws Exception{
if(valores.length()!=2)
trows new Exception("Cantidad de Operandos no válida");
if(op!='+' && op!='-')
trows new Exception("Operación no válida");
OperacionesByte op=new OperacionesByte();
try{
byte v1=(byte)valores[0],v2=(byte)valores[1];
System.out.println((op=='+')?op.suma(v1,v2):op.resta(v1,v2));
}
catch(NumberFormatException e){
try{
short v1=(short)valores[0],v2=(short)valores[1];
System.out.println((op=='+')?(OperacionesShort)op.suma(v1,v2):(OperacionesShort)op.resta(v1,v2));
catch(NumberFormatException e){
try{
int v1=(int)valores[0],v2=(int)valores[1];
System.out.println((op=='+')?(OperacionesInt)op.suma(v1,v2):(OperacionesInt)op.resta(v1,v2));
catch(NumberFormatException e){
try{
long v1=(long)valores[0],v2=(long)valores[1];
System.out.println((op=='+')?(OperacionesLong)op.suma(v1,v2):(OperacionesLong)op.resta(v1,v2));
catch(NumberFormatException e){
throw new Execption("Combinación de Tipos de datos no soportada") ;
}
}
}
}
}
}
}