Advertisement
CrazyDave23

S2 - Actividad 2 - Clase Auto

Aug 16th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.59 KB | None | 0 0
  1. public class Auto {
  2.    
  3.     //Valores por defecto
  4.    
  5.     public static final String TIPO_AUTOMOVIL_DEF = "Mini";
  6.     public static final String TIPO_PINTURA_DEF = "Metalizada";
  7.     public static final String MODALIDAD_SEGURO_DEF = "Terceros";
  8.    
  9.     //Atributos
  10.    
  11.     private String modelo;
  12.     private String color;
  13.     private String matricula;
  14.     private String tipo_automovil;
  15.     private String tipo_pintura;
  16.     private int año;
  17.     private String modalidad_seguro;
  18.    
  19.     //Constructor
  20.    
  21.     public Auto(){
  22.         this("", "", "", TIPO_AUTOMOVIL_DEF, TIPO_PINTURA_DEF, 0, MODALIDAD_SEGURO_DEF);
  23.     }
  24.    
  25.     public Auto(String modelo, String color){
  26.         this(modelo, color, "", TIPO_AUTOMOVIL_DEF, TIPO_PINTURA_DEF, 0, MODALIDAD_SEGURO_DEF);
  27.     }
  28.    
  29.     public Auto(String modelo, String color, String matricula, String tipo_automovil, String tipo_pintura, int año, String modalidad_seguro){
  30.         this.modelo = modelo;
  31.         this.color = color;
  32.         this.matricula = matricula;
  33.         comprobarTipoAutomovil(tipo_automovil);
  34.         comprobarTipoPintura(tipo_pintura);
  35.         this.año = año;
  36.         comprobarModalidad(modalidad_seguro);
  37.     }
  38.    
  39.     //Métodos
  40.    
  41.     @Override
  42.     public String toString(){
  43.         return "Modelo: "+modelo+
  44.                 "\nColor: "+color+
  45.                 "\nMatricula: "+matricula+
  46.                 "\nTipo de Automovil: "+tipo_automovil+
  47.                 "\nTipo de Pintura: "+tipo_pintura+
  48.                 "\nAño Fabriacion: "+año+
  49.                 "\nModalidad de Seguro: "+modalidad_seguro;
  50.     }
  51.    
  52.     public void comprobarTipoAutomovil(String tipo_automovil){
  53.        
  54.         String tipos[] = { "Mini", "Utilitario", "Familiar", "Deportivo" };
  55.         boolean encontrado = false;
  56.        
  57.         for(int i=0; i<tipos.length && !encontrado; i++){
  58.             if (tipos[i].equals(tipo_automovil)){
  59.                 encontrado = true;
  60.             }
  61.         }
  62.        
  63.         if (encontrado){
  64.             this.tipo_automovil = tipo_automovil;
  65.         } else {
  66.             this.tipo_automovil = TIPO_AUTOMOVIL_DEF;
  67.         }
  68.        
  69.     }
  70.    
  71.     public void comprobarTipoPintura(String tipo_pintura){
  72.        
  73.         String pinturas[] = {"Metalizada", "No Metalizada"};
  74.         boolean encontrado = false;
  75.        
  76.         for(int i=0; i<pinturas.length && !encontrado; i++){
  77.             if(pinturas[i].equals(tipo_pintura)){
  78.                 encontrado = true;
  79.             }
  80.         }
  81.        
  82.         if(encontrado){
  83.             this.tipo_pintura = tipo_pintura;
  84.         } else {
  85.             this.tipo_pintura = TIPO_PINTURA_DEF;
  86.         }
  87.        
  88.     }
  89.    
  90.     public void comprobarModalidad(String modalidad_seguro){
  91.        
  92.         String modalidades[] = {"Terceros", "Todo Riesgo"};
  93.         boolean encontrado = false;
  94.        
  95.         for(int i=0; i<modalidades.length && !encontrado; i++){
  96.             if(modalidades[i].equals(modalidad_seguro)){
  97.                 encontrado = true;
  98.             }
  99.         }
  100.        
  101.         if(encontrado){
  102.             this.modalidad_seguro = modalidad_seguro;
  103.         } else {
  104.             this.modalidad_seguro = MODALIDAD_SEGURO_DEF;
  105.         }
  106.        
  107.     }
  108.    
  109.     public void ImprimirAutomovil(String modelo, String color){
  110.         System.out.println("Modelo: "+modelo+"\nColor: "+color);  
  111.     }
  112.  
  113.    
  114.     //Setters y Getters
  115.    
  116.     public String getModelo() {
  117.         return modelo;
  118.     }
  119.  
  120.     public void setModelo(String modelo) {
  121.         this.modelo = modelo;
  122.     }
  123.  
  124.     public String getColor() {
  125.         return color;
  126.     }
  127.  
  128.     public void setColor(String color) {
  129.         this.color = color;
  130.     }
  131.  
  132.     public String getMatricula() {
  133.         return matricula;
  134.     }
  135.  
  136.     public void setMatricula(String matricula) {
  137.         this.matricula = matricula;
  138.     }
  139.  
  140.     public String getTipo_automovil() {
  141.         return tipo_automovil;
  142.     }
  143.  
  144.     public void setTipo_automovil(String tipo_automovil) {
  145.         this.tipo_automovil = tipo_automovil;
  146.     }
  147.  
  148.     public String getTipo_pintura() {
  149.         return tipo_pintura;
  150.     }
  151.  
  152.     public void setTipo_pintura(String tipo_pintura) {
  153.         this.tipo_pintura = tipo_pintura;
  154.     }
  155.  
  156.     public int getAño() {
  157.         return año;
  158.     }
  159.  
  160.     public void setAño(int año) {
  161.         this.año = año;
  162.     }
  163.  
  164.     public String getModalidad_seguro() {
  165.         return modalidad_seguro;
  166.     }
  167.  
  168.     public void setModalidad_seguro(String modalidad_seguro) {
  169.         this.modalidad_seguro = modalidad_seguro;
  170.     }
  171.    
  172.    
  173.    
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement