EJERCICIO DE REFACTORIZACIÓN

A continuación mostramos el código de una clase refactorizada:

/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
 */
package javaapplication6;

/**
 *
 * @author joaquin
 */
public class JavaApplication6 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        int[] listaNumeros = new int[100];
        // TODO code application logic here
        for (int i=0; i<listaNumeros.length ; i++) {
            int numero = (int) (Math.random() * 100) + 1;
            listaNumeros[i] = numero;            
        }
        System.out.println("El número mayor es " + numeromayor(listaNumeros));
    }
    
    public static int numeromayor( int[] listaNumeros) {
        int numeroMayor=0;
        for (int numeroActual : listaNumeros) {
            if (numeroActual > numeroMayor) {
                numeroMayor = numeroActual;
            }
        }
        return numeroMayor;
        
    }
    
}

El proyecto original se puede descargar desde aquí:

EJERCICIO PROPUESTO

Refactorizar el código dado en el siguiente proyecto

EJERCICIO PROPUESTO 02

Refactorizar y documentar el siguiente código:

import java.time.LocalDate;

import modelo.Persona;

public class App {
    public static void main(String[] args) throws Exception {
        LocalDate f = LocalDate.now();
        System.out.println(fecha.getDayOfMonth());
        System.out.println(fecha.getMonthValue());
        Persona pepe = new Persona("Pepe");
        pepe.setFechaNacimiento("2002-11-04");
    }
}


public class Persona {
    private final String nombre;
    private String apel; 
    private int numTelefono;
    private String email;
    private LocalDate fechaNacimiento;


    public String getNombre() {
        return nombre;
    }

    public LocalDate getFechaNacimiento() {
        return fechaNacimiento;
    }
    public void setFechaNacimiento(LocalDate fechaNacimiento) {
        this.fechaNacimiento = fechaNacimiento;
    }

    public int comprobarCumpleanyos() {
        LocalDate hoy = LocalDate.now();
        if (hoy.getDayOfMonth()==getFechaNacimiento().getDayOfMonth() &&
        hoy.getMonthValue()==getFechaNacimiento().getMonthValue()) {
            return hoy.getYear() - getFechaNacimiento().getYear();   
        }
        else {
            return -1;
        }
    }
}

La solución propuesta se puede descargar aqui