在我的Java教科书中关于数组的一章中,我正在进行一项指定,其中说:
使用第五章中的问题类来定义一个测试类。一个小测验可以由多达25个问题组成。定义测试类的add方法,将一个问题添加到一个小测验中。定义测试类的giveQuiz方法,将一个问题添加到一个小测验中。定义测试类的giveQuiz方法,将每个问题依次呈现给用户,接受每个问题的答案,并跟踪结果。使用一个主方法定义一个名为QuizTime的类,该方法选择测试的问题,向用户展示测试,收集和检查答案,并打印最终结果。
我正在考虑的这项任务的程序开发计划可能是正确的,也可能是不正确的,在这里:
5.跟踪答案的结果
6.创建另一个名为QuizTime的类
8.使方法允许将问题作为数组输入到方法的参数中。
9.储存和核对答案
在我看来,这似乎是在要求总共制作3个类和一个主要方法。
然而,我感到困惑,为什么要有这么多的课程。下面给出的问题类中的方法似乎有一些方法可以执行赋值要求程序员做的事情,但是这些方法看起来是空的,没有用。我也对6-10的程序开发计划感到困惑。我不知道如何制作数组来将问题和答案存储到方法中。
以下是Java教科书中已经给出的问题类:
//********************************************************************
// Question.java Author: Lewis/Loftus/Cocking
//
// Represents a question (and its answer).
//********************************************************************
public class Question implements Complexity
{
private String question, answer;
private int complexityLevel;
//-----------------------------------------------------------------
// Sets up the question with a default complexity.
//-----------------------------------------------------------------
public Question (String query, String result)
{
question = query;
answer = result;
complexityLevel = 1;
}
//-----------------------------------------------------------------
// Sets the complexity level for this question.
//-----------------------------------------------------------------
public void setComplexity (int level)
{
complexityLevel = level;
}
//-----------------------------------------------------------------
// Returns the complexity level for this question.
//-----------------------------------------------------------------
public int getComplexity()
{
return complexityLevel;
}
//-----------------------------------------------------------------
// Returns the question.
//-----------------------------------------------------------------
public String getQuestion()
{
return question;
}
//-----------------------------------------------------------------
// Returns the answer to this question.
//-----------------------------------------------------------------
public String getAnswer()
{
return answer;
}
//-----------------------------------------------------------------
// Returns true if the candidate answer matches the answer.
//-----------------------------------------------------------------
public boolean answerCorrect (String candidateAnswer)
{
return answer.equals(candidateAnswer);
}
//-----------------------------------------------------------------
// Returns this question (and its answer) as a string.
//-----------------------------------------------------------------
public String toString()
{
return question + "\n" + answer;
}
}下面是我创建的一个测试类,在这个类中,我没有做过太多的工作。
public class Quiz
{
private String add;
public String addQuest (String addQ)//adds questions to quiz
{
add = addQ;
return add;//returninng the question
}
public String giveQuiz ()//give the quiz to the user
{
//accept and store each answer
return;
}
}QuizTime类:
public class QuizTime
{
private String question;
public String[] Quiz() {
}
public String toString(String quest)
{
question = quest;
for (int i = 0; i < 25; i++)
Quiz[i] = new Quiz (question);
}
public String presents ()
{
for (int i = 0; i < 25; i++)
return quest[i];
}
}我还没有提出主要的方法,因为我仍然不知道这些类的开发将如何工作。我为我在课堂和数组方面的低技能而道歉,因为我刚刚学会了它们。我非常感谢你们提前提供的帮助。
对于Quiz类,在第一个方法中,我尝试让主方法插入可以存储在方法中的问题的参数。但我想知道是否有一个更容易的方法来存储25个参数的问答在方法中,如果这是可能的。我正在努力,请让我知道我是否在正确的轨道上。非常感谢。
发布于 2016-12-14 00:37:01
但是我想知道是否有一种更容易的方法在方法中存储25个小测验问题的参数,如果可能的话。
有不需要有25个参数的问答问题。这就是为什么你被期望使用来自你学校的数组。
看起来会是这样的:
public Question[] getQuestions(){
return questions;
}出于任何原因,如果您需要通过一个方法传递所有问题,它将如下所示:
public void sendQuestions(Question[] ques){
//do whatever
}https://stackoverflow.com/questions/41132815
复制相似问题