I have 2 classes; The first has this code:
public class Artigo {
private String descricao;
private double preco;
private int stockCorrente;
public Artigo(String descricao, double preco){
Artigo(descricao, preco, 0);
}
private void Artigo(String descricao, double preco, int stockCorrente){
this.descricao = descricao;
if (preco < 0 || stockCorrente < 0) {
System.out.println("Erro: Valores negativos.");
System.exit(0);
} else
this.preco = preco;
this.stockCorrente = stockCorrente;
}
public String getDescricao(){
return descricao;
}
public double getPreco(){
return preco;
}
public void setPreco(double preco){
this.preco = preco;
}
public int getStockCorrente(){
return stockCorrente;
}
public boolean isStockEnough(int nUnits){
if (stockCorrente < nUnits){
return false;
}else{
return true;
}
}
public boolean sell(int nUnits){
if (isStockEnough(nUnits)){
stockCorrente = stockCorrente - nUnits;
return true;
}else{
return false;
}
}
public void recharge(int nUnits){
stockCorrente = nUnits;
}
public boolean equals(Artigo otherProducts){
return this.descricao.equalsIgnoreCase(otherProducts.descricao);
}
public String toString(){
return descricao + ", preço: " + preco + ", stock: " + stockCorrente;
}
And then my other class:
public class Pack {
private String descricao;
private int nArtigos;
private double DESCONTO;
public Pack(String descricao, double desconto){
this.descricao = descricao;
this.DESCONTO = desconto;
}
public String getDescricao(){
return descricao;
}
public int getnArtigos(){
return nArtigos;
}
public double getDesconto(){
return DESCONTO;
}
public int getStockCorrente(){
return stockCorrente;
}
public boolean equals(Pack otherpacks){
return this.descricao.equalsIgnoreCase(otherpacks.descricao);
}
public String toString(){
return descricao + " com os artigos [ " + " ], com desconto de " + DESCONTO + ", com preco de " + "PRECO" + ", com stock corrente de " + "STOCK" ;
}
public boolean existArtigo(Artigo otherProducts){
}
public boolean addArtigo(Artigo newArtigo){
}
public boolean haveStock(int nUnits){
}
public boolean sell(int nUnits){
}
public double getPreco(){
}
In this class, all the methods are required and needed. The biggest part of them are empty because I don't know what to do in there. I mean, I know what to do, what I don't know it HOW to do.
The request is: Add articles to the pack, get the name and the current stock of each. Here I need to get them connecting with the methods of the other class, right? But How?