把代码格式化以下
时间: 2024-02-09 16:08:37 浏览: 16
好的,以下是格式化后的代码:
```
private int calculateScore() {
int singleChoiceScore = 0;
int multiChoiceScore = calculateMultiChoiceScore();
// 计算单选题得分
RadioGroup singleChoiceGroup = findViewById(R.id.rg_1);
int selectedSingleChoiceId = singleChoiceGroup.getCheckedRadioButtonId();
if (selectedSingleChoiceId == R.id.rb_1) {
singleChoiceScore = 50;
}
return singleChoiceScore + multiChoiceScore;
}
private int calculateMultiChoiceScore() {
CheckBox[] checkBoxes = new CheckBox[] {
findViewById(R.id.ck_1),
findViewById(R.id.ck_2),
findViewById(R.id.ck_3),
findViewById(R.id.ck_4),
findViewById(R.id.ck_5)
};
int checkedCount = 0;
for (int i = 0; i < checkBoxes.length; i++) {
if (checkBoxes[i].isChecked()) {
checkedCount++;
}
}
switch (checkedCount) {
case 0:
return 0;
case 2:
return 20;
case 3:
return 30;
case 4:
return 50;
default:
return 0;
}
}
private String calculateGrade(int score) {
switch (score / 10) {
case 6:
return "合格";
case 7:
return "良好";
case 8:
case 9:
case 10:
return "优秀";
default:
return "不及格";
}
}
```