为生成房屋名称,一个街区的一侧有10座房屋,总共20座。街区一侧的房屋以字母A-J表示,街区另一侧的房屋以相同的字母表示,但带有2个相同的字母(例如AA,BB,...)。
House[][] houses = new House[1000][1000];
for (int i = 0; i < houses.length; i++) {
for (int j = 0; j < houses.length; j++) {
House h = new House(i, j, ""); //Need some way to designate
letters for each house
}
}
//House class
public class House {
private int streetnum;
private int avnum;
private String houseletter = "";
public House(int streetnum, int avnum, String houseletter) {
streetnum = this.streetnum;
avnum = this.avnum;
houseletter = this.houseletter;
}
public int getStreetNum() {
return streetnum;
}
public int getAvNum() {
return avnum;
}
public String getHL() {
return houseletter;
}
}
答案 0 :(得分:0)
不确定这是否回答了您的问题,但是在House
类的构造函数中,应该以相反的方式编写赋值。 this
指正在创建的House
的当前实例。
public House(int streetnum, int avnum, String houseletter) {
this.streetnum = streetnum;
this.avnum = avnum;
this.houseletter = houseletter;
}