英文:
How do I understand the public static Objective[]?
问题
public class Objective {
private int problemNumber; // 原始棋盘游戏中的问题编号
private String initialState; // 初始图块摆放列表
public static Objective[] OBJECTIVES = {
// 初始任务
new Objective("S0S6W3N8N2E5S7S18", 1),
new Objective("N7N0S3N8S2S6E1S51", 2),
new Objective("W8S6E2S5N0E4W1S31", 3),
new Objective("S8S7W0E5S4N2W3S13", 4),
new Objective("S1N2W0E7S6S8W3W58", 5),
new Objective("W8N6E7S4N0W1N2S32", 6),
new Objective("S2N0W1E8S7W4W6W38", 7),
new Objective("S6N8W5E4W7W1S3N23", 8),
new Objective("S3S7W6S4W1E5N2S05", 9),
new Objective("S0S1N2N7S6W3N4S57", 10),
new Objective("E2N8W7N1S6E4S3S06", 11),
new Objective("N1S3W0W7N5E8E6S28", 12),
// 更多任务...
};
public static Objective newObjective(int difficulty) {
assert difficulty >= 0 && difficulty <= 4;
return OBJECTIVES[0]; // 待修正 第5任务 (P)
}
public String getInitialState() {
return initialState;
}
public int getProblemNumber() {
return problemNumber;
}
public static Objective getObjective(int index) {
return OBJECTIVES[index];
}
public static Objective[] getOBJECTIVES() {
return OBJECTIVES;
}
}
Please let me know if you need any further assistance or explanation about the code.
英文:
public class Objective {
private int problemNumber; // The problem number from the original board game
private String initialState; // The list of initial tile placements
public static Objective[] OBJECTIVES = {
// STARTER
new Objective("S0S6W3N8N2E5S7S18", 1),
new Objective("N7N0S3N8S2S6E1S51", 2),
new Objective("W8S6E2S5N0E4W1S31", 3),
new Objective("S8S7W0E5S4N2W3S13", 4),
new Objective("S1N2W0E7S6S8W3W58", 5),
new Objective("W8N6E7S4N0W1N2S32", 6),
new Objective("S2N0W1E8S7W4W6W38", 7),
new Objective("S6N8W5E4W7W1S3N23", 8),
new Objective("S3S7W6S4W1E5N2S05", 9),
new Objective("S0S1N2N7S6W3N4S57", 10),
new Objective("E2N8W7N1S6E4S3S06", 11),
new Objective("N1S3W0W7N5E8E6S28", 12),
", 53),
public static Objective newObjective(int difficulty) {
assert difficulty >= 0 && difficulty <= 4;
return OBJECTIVES[0]; // FIXME Task 5 (P)
}
public String getInitialState() {
return initialState;
}
public int getProblemNumber() {
return problemNumber;
}
public static Objective getObjective(int index) {
return OBJECTIVES[index];
}
public static Objective[] getOBJECTIVES() {
return OBJECTIVES;
}
I just learn Java for two weeks, I still have some questions about this code.
public static Objective[] OBJECTIVES =
I don't understand this code. Is a method of the class?
public static Objective newObjective(int difficulty)
I also have no idea about this code.
答案1
得分: 1
public static Objective[] OBJECTIVES = { ...
这是一个已实例化的Objective对象数组。该数组的可见性为public,且是静态的,因此它只会在该类中被创建一次。需要注意的一点是,Objective对象不是不可变的,因此不应全部使用大写字母来定义,因为它本质上是可变的。
public static Objective newObjective(int difficulty)
代码表明应基于提供的难度级别返回一个新的Objective对象。我推测这指的是底层数组中的索引。
不过,这个问题明显需要更多的焦点。在将来,请提一个只有一个焦点的问题,并在可能的情况下提问时清晰明了。
英文:
> public static Objective[] OBJECTIVES = { ...
This is an array of Objective objects that has been instantiated. The visibility of this array is public and the array is static so it is only created once for the Class. One thing to note is that Objective
is not immutable and so this shouldn't
be defined with all uppercase letters because it is inherently mutable.
> public static Objective newObjective(int difficulty)
The code suggests that a new Objective object should be returned based on the difficulty provided. I presume that refers to an index in the underlying array.
This question definitely needs more focus though. In the future ask a single question with a single point of focus and be clear when asking if possible.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论