domingo, 2 de octubre de 2011

Como Programar en Java: Ejercicio 5.29

Aquí esta el ejercicio 5.29 de Como Programar en Java séptima edición.

package com.jlm.ccb.ejercicios.capitulocinco;

/**
 * Clase encargada de imprimir Twelve Days
 * Ejercicio 5.29
 * @author LorettoTG
 * @version 1.0
 */
public class DoceDias {
    /**
     * Método encargado de imprimir la cancion de los
     * doce dias.
     */
    public void imprimir() {
        for (int dia = 1; dia <= 12; dia++) {
            switch(dia) {
            case 1:
                System.out.print("One ");
                imprimirFragmento(dia);
                break;
            case 2:
                System.out.print("Two ");
                imprimirFragmento(dia);
                break;
            case 3:
                System.out.print("Three ");
                imprimirFragmento(dia);
                break;
            case 4:
                System.out.print("Four ");
                imprimirFragmento(dia);
                break;
            case 5:
                System.out.print("Five ");
                imprimirFragmento(dia);
                break;
            case 6:
                System.out.print("Six ");
                imprimirFragmento(dia);
                break;
            case 7:
                System.out.print("Seven ");
                imprimirFragmento(dia);
                break;
            case 8:
                System.out.print("Eight ");
                imprimirFragmento(dia);
                break;
            case 9:
                System.out.print("Nine ");
                imprimirFragmento(dia);
                break;
            case 10:
                System.out.print("Ten ");
                imprimirFragmento(dia);
                break;
            case 11:
                System.out.print("Eleven ");
                imprimirFragmento(dia);
                break;
            case 12:
                System.out.print("Twelve ");
                imprimirFragmento(dia);
                break;
            }
        }
    }

    /**
     * Método encargado de imprimir fragmentos de
     * la cancion correspondiente al día.
     * @param dia int Con el fragmento correspondiente
     * al día.
     */
    public void imprimirFragmento(int dia) {
        switch(dia) {
        case 1:
            System.out.println("True Love refers to God");
            break;
        case 2:
            System.out.println("Turtle Doves refers to the Old "
                    + "and New Testaments");
            break;
        case 3:
            System.out.println("French Hens refers to Faith, "
                    + "Hope and Charity, the Theological Virtues");
            break;
        case 4:
            System.out.println("Calling Birds refers to the Four "
                    + "Gospels and/or the Four Evangelists");
            break;
        case 5:
            System.out.println("Golden Rings refers to the first Five "
                    + "Books of the Old Testament, the \"Pentateuch\", "
                    + "which gives the history of man's fall from grace.");
            break;
        case 6:
            System.out.println("Geese A-laying refers to the six days "
                    + "of creation");
            break;
        case 7:
            System.out.println("Swans A-swimming refers to the seven gifts "
                    + "of the Holy Spirit, the sacraments");
            break;
        case 8:
            System.out.println("Maids A-milking refers to the eight "
                    + "beatitudes");
            break;
        case 9:
            System.out.println("Ladies Dancing refers to the nine Fruits of "
                    + "the Holy Spirit");
            break;
        case 10:
            System.out.println("Lords A-leaping refers to the ten "
                    + "commandments");
            break;
        case 11:
            System.out.println("Pipers Piping refers to the eleven "
                    + "faithful apostles");
            break;
        case 12:
            System.out.println("Drummers Drumming refers to the points of "
                    + "doctrine in the Apostle's Creed");
            break;
        }
    }

    /**
     * Punto de entrada a la clase y a la aplicación.
     * @param args matriz de argumentos de cadena.
     */
    public static void main(String[] args) {
        //El operador new es el encargado de crear instancias de
        //una clase, es decir los objetos que tienen las características
        //de la clase. El operador new de Java es capaz de reservar la
        //memoria para un objeto de este tipo sabiendo los atributos que
        //tiene según la definición de la clase.
        DoceDias doceDias = new DoceDias();
        doceDias.imprimir();
    }
}

1 comentario: