-2
There’s an issue that I need to resolve urgently:
Consider the code Venda.java
.
Remove the responsibility of keeping information from items sold in the class Venda
, creating a new class ItemDeVenda
.
import java.util.ArrayList;
import java.util.List;
public class Venda {
private List<Double> itemValores = new ArrayList<Double>();
private List<Double> itemQuantidades = new ArrayList<Double>();
public double total() {
double soma = 0;
for (int i = 0; i < itemValores.size(); i++) {
soma += itemValores.get(i) * itemQuantidades.get(i);
}
return soma;
}
public void adicionarItem(double valor) {
itemValores.add(valor);
itemQuantidades.add(1.0);
}
public void adicionarItem(double valor, double quantidade) {
itemValores.add(valor);
itemQuantidades.add(quantidade);
}
}
Accounts receivable and sale is always urgent :). I will prepare the receipt now.
– rray
What’s your real question?
– cantoni
How could I remove the liabilities of the sold items from the Sale class and put in the new class(Itemdevenda).
– Diogo Nazareno
So @Diogonazareno, I think you should rephrase your question, trying to show what you’ve tried to do. Hardly anyone here will be willing to settle this issue without you showing an effort. Your question is very interesting, because it deals with essential aspects of programming, mainly OO programming. Separation of responsibility is fundamental and your question goes in this aspect.
– cantoni
Look for responsibility in the O.R. There’s a lot of good stuff in there. Example: http://answall.com/questions/81314/o-que-s%C3%A3o-os-conceitos-de-coes%C3%A3o-e-acoplamento
– cantoni
@Cantoni, I’m on. Thank you :)
– Diogo Nazareno