I am using BlueJ for this assignment I have and I have a problem doing this part of the question which is to put decision constructs to ensure that invalid data is not set which I have already tried.In which I placed the if else statement in the setName portion which does not work. The code will show error if I have put 1 in the GraphicIllustrators main void portion for setName. So where do I need to put the if else statement in the code below.BTW I am using inheritance to do this.So please advise.Thanks!
The coding for the main class:
public class Publishing_Inc
{
private int ID=0;
private String name="-Name Needed-";
private int level=0;
private String jobtitle="-Title Needed-";
private String edit="-Edit Skill-";
public void calculateID(){
int uniqueID;
uniqueID =((int)( Math.random()*10000)+1);
ID = uniqueID;
}
public int getID(){
return ID;
}
public void setName(String d) {
name = d;
}
public String getName() {
return name;
}
public void setTitle(String b){
jobtitle=b;
}
public String getTitle() {
return jobtitle;
}
public void calculatelevel(){
int uniquelevel;
uniquelevel =((int)( Math.random()*3)+1);
level = uniquelevel;
}
public int getlevel() {
return level;
}
public void setEdit(String z){
edit=z;
}
public String getEdit() {
return edit;
}
}
The sub class:
public class GraphicIllustrators extends Publishing_Inc
{
public void displayGraphInformation() {
System.out.println("ID: " + getID());
System.out.println("Name:" + getName());
System.out.println("Job Title: " + getTitle());
System.out.println("Level: " + getlevel());
System.out.println();
}
public static void main (String args[]) {
GraphicIllustrators graphic = new GraphicIllustrators ( );
graphic.calculateID ( );
graphic.setName (" Tim Cook" );
graphic.calculatelevel ();
graphic.setTitle ("Graphic Illustrators" );
graphic.displayGraphInformation( );
}
}
Aucun commentaire:
Enregistrer un commentaire