samedi 15 avril 2017

Rewriting the code so that its readability is improved without changing its behaviours(2)

public class Question1d { private static class Product {

    public int type;
    public static final int BOOK = 1;
    public static final int CD = 2;
}

public int getPrice(Product[] products) {

    int total = 0;

    for (Product p : products) {
        if (p.type == Product.BOOK) {
            total += 17;
        } else {
            total += 22;
        }
    }
    return total;
}

}

Hello, I also brought up a new different question. I have to manipulate this code without triggering any issues of design and pattern principles.

Aucun commentaire:

Enregistrer un commentaire