我有一类不同部分的问题 - 根据其他答案向用户显示某些部分。第1节总是得到回答。第2节&只有在某些情况下才会回答3。
我应该如何最好" group"这些问题,以便我可以轻松检查给定组中的真实答案的总数(包含true
/ false
)并检查这些部分是否每个问题回答
问题中的数据是从Spring项目中的Web UI返回的。我认为可能的值为true
,false
或null
。
@Entity
public class LicenseApplication {
// Section 1
private boolean question1;
private boolean question2;
//Section 2
private boolean question3;
private boolean question4;
}
答案 0 :(得分:0)
你可以做类似以下的事情
class Section
{
public List<Question> questions;
//...
}
class Question
{
public boolean isCorrect;
//...
}
public boolean entireSectionCorrect(Section section)
{
for (int i=0; i<section.questions.size(); i++) {
if(!section.questions[i].isCorrect)
return false;
}
return true;
}
答案 1 :(得分:0)
@AlanCPSC提出了很好的建议,因为纠正了一些事情
class Section
{
private List<Question> questions;
public int getCount()
{
int count=0;
for(Question quest : questions)
{
boolean answer = quest.getAnswer().get(quest.getQuestion());
boolean answered = quest.getAnswered().get(quest.getQuestion());
if(answer == answered)
{
count++;
}
}
return count;
}
...
}
class Question
{
private String question;
private Map<String, Boolean> answer; // correct answer
private Map<String, Boolean> answered; // answered by candidate
...
}
答案 2 :(得分:0)
我对OP的混乱以及其他答案的过分感到有些失望,所以这是我的看法......
免责声明:我已经离开java一段时间了,而且我已经通过记忆对此进行了编码...原谅任何错误(但请指出它们以便我解决它们)。
var displayMatches = function(){
let val = this.value;
console.log(val);
var matchArray = findMatches(val, cities);
var html = matchArray.map(function(place){
console.log(this, place, "test");
var regex = new RegExp(val, 'gi');
var cityName = place.city.replace(regex, "<span class='hl'>" + val + "</span>");
var stateName = place.state.replace(regex, "<span class='hl'>" + val + "</span>");
return `
<li>
<span class="name">${cityName}, ${stateName}</span>
<span class="population">${place.population}</span>
</li>
`;
}).join("");
suggestions.innerHTML = html;
}