谁帮我做下这道java的题呀
创建checkAnswer方法实现不定项选择判分,具体要求如下:1)考生答案和正确答案相同(不考虑选项顺序),得5分。2)考生答案不全,得2分。3)考生答案中有错误答案,...
创建checkAnswer方法实现不定项选择判分,具体要求如下:
1)考生答案和正确答案相同(不考虑选项顺序),得5分。
2)考生答案不全,得2分。
3)考生答案中有错误答案,得0分。
部分示例如下:
正确答案 考生答案 得分
ABC ABC/ACB/BAC/CBA/BCA 5
ABC A/B/C/AB/AC/BC/CB/CA/BA 2
ABC D/AD/BD/CD/ABD/BCD/ACD/ABCD 0
————————————————————————————————————
public class JavaMethod {
public static int checkAnswer(String correctAnswer,String userAnswer){
}
public static void main(String[] args) {
String correctAnswer = "ACD";
String userAnswer = "AD";
int grade = checkAnswer(correctAnswer,userAnswer);
System.out.println("本题的得分是 : " + grade);
}
}
———————————————————————————————————— 展开
1)考生答案和正确答案相同(不考虑选项顺序),得5分。
2)考生答案不全,得2分。
3)考生答案中有错误答案,得0分。
部分示例如下:
正确答案 考生答案 得分
ABC ABC/ACB/BAC/CBA/BCA 5
ABC A/B/C/AB/AC/BC/CB/CA/BA 2
ABC D/AD/BD/CD/ABD/BCD/ACD/ABCD 0
————————————————————————————————————
public class JavaMethod {
public static int checkAnswer(String correctAnswer,String userAnswer){
}
public static void main(String[] args) {
String correctAnswer = "ACD";
String userAnswer = "AD";
int grade = checkAnswer(correctAnswer,userAnswer);
System.out.println("本题的得分是 : " + grade);
}
}
———————————————————————————————————— 展开
2个回答
展开全部
public static int checkAnswer(String correctAnswer, String userAnswer)
{
int grade = 0;
int num = 0;
for (int i = 0; i < userAnswer.length(); i++)
{
// 如果用户答案某一项在正确答案中
if (correctAnswer.indexOf(userAnswer.charAt(i)) != -1)
{
num++;
}
// 如果用户答案某一项不在正确答案中(即有错误选择项)
else
{
return grade = 0;
}
}
if (num == 0)
{
grade = 0;
}
else if (num == correctAnswer.length())
{
grade = 5;
}
else
{
grade = 2;
}
return grade;
}
public static void main(String[] args)
{
String correctAnswer = "ABC";
String userAnswer = "D";
int grade = checkAnswer(correctAnswer, userAnswer);
System.out.println("本题得分 : " + grade);
}
展开全部
public static int checkAnswer(String correctAnswer, String userAnswer) {
if (userAnswer == null || userAnswer.isEmpty()) {
return 0;
}
if (correctAnswer == null || correctAnswer.isEmpty()) {
throw new RuntimeException("No answer question!");
}
int right = 0;//正确的次数
for (char char0 : userAnswer.toCharArray()) {
if (correctAnswer.indexOf(char0) < 0) {
return 0;//一旦有一个不正确
} else {
right++;//记录正确的次数
}
}
return right == correctAnswer.length() ? 5 : 2;
}
public static void main(String[] args) {
String correctAnswer = "ACD";
String userAnswer = "ACD";
int grade = checkAnswer(correctAnswer, userAnswer);
System.out.println("本题的得分是 : " + grade);
}
if (userAnswer == null || userAnswer.isEmpty()) {
return 0;
}
if (correctAnswer == null || correctAnswer.isEmpty()) {
throw new RuntimeException("No answer question!");
}
int right = 0;//正确的次数
for (char char0 : userAnswer.toCharArray()) {
if (correctAnswer.indexOf(char0) < 0) {
return 0;//一旦有一个不正确
} else {
right++;//记录正确的次数
}
}
return right == correctAnswer.length() ? 5 : 2;
}
public static void main(String[] args) {
String correctAnswer = "ACD";
String userAnswer = "ACD";
int grade = checkAnswer(correctAnswer, userAnswer);
System.out.println("本题的得分是 : " + grade);
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |