I am a beginner in java, and I have a homework which I can't really solve. I have to write a program in which we can add labels and reference numbers to an article. If we enter the reference number and the length is shorter than 3 digits then it should return " ". If we already entered a reference number and we want to write a new one with again less than a 3 digit number then the previous number shouldn't change. How do I do this? I would really appreciate any help`Here is the code:
public class Article
{
private String label;
private String ref = " ";
public Article (String lab){
this.label = lab;
}
public String getLabel(){
return this.label;
}
public void setReferencenumber ( String refnumber ){
this.ref = refnumber;
if (refnumber.length() < 3){this.ref=this.ref;
}
}
public String getReferencenumber()
{
return this.ref;
}}`
Aucun commentaire:
Enregistrer un commentaire