Advertisement
AgusSaavedra

Eslabon

Oct 25th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Eslabon {
  2.    
  3.     private int numeroActual;
  4.     private double longitudActual;
  5.    
  6.     /**
  7.      * pre: numero y longitud tienen que ser positivos y diferentes de 0.
  8.      * post: inicializa el Eslabón con el numero y la longitud indicados.
  9.      */
  10.  
  11.     public Eslabon (int numero, double longitud){
  12.        
  13.           if (numero <= 0 || longitud <= 0.0){
  14.              
  15.               Error numeroOLongitudInexistentes = new Error("No existe numero y/o longitud negativa o nula");
  16.               throw numeroOLongitudInexistentes;
  17.          
  18.           } else {
  19.              
  20.               numeroActual = numero;
  21.               longitudActual = longitud;
  22.           }    
  23.     }
  24.    
  25.     /**
  26.      * post: Devuelve el número de Eslabón.
  27.      */
  28.    
  29.     public int obtenerNumero(){
  30.        
  31.         return numeroActual;
  32.     }
  33.    
  34.     /**
  35.      * post: devuelve la longitud del eslabón.
  36.      */
  37.    
  38.     public double obtenerLongitud(){
  39.        
  40.         return longitudActual;
  41.        
  42.     }
  43.  
  44.     /**
  45.      * pre: La Longitud no puede ser nula o negativa.  
  46.      * post: Cambia la longitud actual del Eslabon.
  47.      */
  48.     public void CambiarLongitud(double nuevaLongitud) {
  49.        
  50.         if (nuevaLongitud <=0){
  51.                
  52.             Error longitudInexistente = new Error("No existe longitud negativa o nula");
  53.             throw longitudInexistente;
  54.        
  55.         } else {
  56.            
  57.             longitudActual = nuevaLongitud;
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement