object - Java Get Constructor Created in a Different Class -


i have constructor mappafermi() creates object class settore attributes coordinatax=10,coordinatay=8 , settorenome=nome.alieni

public class mappafermi extends mappa {     public mappafermi() {         new alieni(10,8);     }  } 

this class settore

public class settore {         private nome settorenome;         private char letterax;         private final int coordinatax;         private final int coordinatay;      public settore (int coordinatax, int coordinatay){         this.coordinatax=coordinatax;         this.coordinatay=coordinatay;     }     public int getx(){         return coordinatax;     }     public int gety(){         return coordinatay;     }     public nome getsettorenome() {         return settorenome;     }     public void setsettorenome(nome settorenome) {         this.settorenome = settorenome;     }  } 

this enum nome attribute settorenome

  public enum nome {         sicuro, pericoloso, scialuppa, alieni, umani     } 

this subclass alieni class settore sets settorenome nome.alieni

public class alieni extends settore {     public alieni(int coordinatax, int coordinatay) {         super(coordinatax, coordinatay);         setsettorenome(nome.alieni);     } } 

this class mappa superclass mappafermi don't think involved question

public class mappa {     private name mappaname;     private final settore [][] settore;     private int matrice [][];     private static final int x=23;     private static final int y=14;      public mappa (){         settore = new settore[x][y];         (int i=0; < x; i++){             (int j=0; j<y; j++) {                 settore[i][j] = new settore (i,j);             }         }     }      public name getmappaname() {         return mappaname;     }      public void setmappaname(name mappaname) {         this.mappaname = mappaname;     } } 

ok, here question, when create object mappafermi creates @ same time object settore, wanna use method getsettorenome() class settore object. know should start creating local variable mappa = new mappafermi() don't know how settore(10,8) settorenome=nome.alieni created in new mappafermi().

public class mappafermitest {     @test     public void testsettorealieni(){         mappa mappa = new mappafermi();         settore settore = ??????;         assertequals(nome.alieni, settore.getsettorenome());     } } 

in mappafermi, not storing alieni created?

public mappafermi() {     new alieni(10,8); // creating, not assigning } 

so there isn't way alieni thingy.

you have declare member of mappafermi, , create getter function getting it.

e.g.

public class mappafermi extends mappa {      private alieni alieni;      public mappafermi() {         alieni = new alieni(10,8);     }      public alieni getalieni() { return alieni; }  } 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -