Making a Java quiz with Classes
I have to make yet another quiz and I am COMPLETELY lost.
I have to make use of classes, so one java file that uses the class file of another java code that tells the other what to do.
I have one class file containing:
Code java:
/**
Rectangle class, phase 3
Under construction!
*/
public class FillInBlank
{
private String question;
private String answer;
private String cans; // correct ans
private String gans; // given ans
/** Constructor
*/
public FillInBlank(String Q, String A) // Question and Answer
{
question = Q;
cans = A;
}
public String getQuestion()
{
return question;
}
public String getcans()
{
return cans;
}
public String getgans()
{
return gans;
}
public void setans(String correctAns)
{
cans = correctAns;
}
public boolean check()
{
if (gans.equals(cans))
return true;
else
return false;
}
//needs setter for given ans
}
Then I have another java file that has the actual quiz in it but I am SO lost of where to go from here
Code java:
import java.util.Scanner;
public class HW7
{
public static void main(String[] args)
{
String input;
Scanner keyboard = new Scanner(System.in);
FillInBlank Q1 = new FillInBlank("What programming lang?","java");
FillInBlank Q2 = new FillInBlank("what command makes summary","javadoc");
System.out.println(Q1.getQuestion());
input = keyboard.nextLine();
}
How do I get a user's answer and how do I output if it's correct or not.
I am sorry if I am being very vague but to be honest not even I understand what my professor wants this week.
Re: Making a Java quiz with Classes
I would have it show a GUI to make things a bit easier
I would have in that gui your question on top then 4 buttons which can lead to new windows and one which will go to the next window and also have the answer next to the button.
Good luck
Re: Making a Java quiz with Classes
Quote:
How do I get a user's answer
If this is a console window application, you can use one of the next... methods of the Scanner class to read input from a user.
Then use an if statement to test if the input is correct.