java - How to call a constructor from a different class -
the constructor mappafermi() sets attribute mappaname of class mappa() , attribute settorenome of 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; } } .
public enum nome { sicuro, pericoloso, scialuppa, alieni, umani } .
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; } } .
public class mappafermi extends mappa { public mappafermi() { setmappaname(name.fermi); new alieni(10,8);//this creates new object settore coordinatax= 10, coordinatay=8 , settorenome=nome.alieni new umani(10,9); } } i'm doing junit test verify value of attribute settorenome of settore(10,8) indeed alieni when run constructor mappafermi(). don't know how should run method getsettorenome() it.
public class mappafermitest { @test public void testsettorealieni(){ mappa mappa = new mappafermi(); settore settore = //when run mappafermi() runs new alieni(10,8) want settore(10,8) using settore settore can settorenome using getsettorenome() assertequals(nome.alieni, settore.getsettorenome()); } }
Comments
Post a Comment