Java - Reading a question from a file and presenting it to a user
Create an application that reads a question from a file and presents it to the user. The answer should also be in the text file. The program should validate whether an answer given by the user in a text box is correct. If it is it writes a certificate of achievement to a text file. If not, it writes a letter of consolation.
Start by creating a text file with two lines. The first line should have a question and the second should have an answer. Now create a Question class. Here is a skeleton:
public class Question
{
private String question;
private String answer;
public Question()
{
// read the question and answer from the text file and put the question in the question variable and the answer in the answer variable
}
// create getter methods for the class
public String getQuestion()
{
}
public String getAnswer()
{
}
public void writeCertificate()
{
// open a file and write a congratulatory certificate in it
}
public void writeConsolationLetter()
{
// open a file and write a consolation letter
}
public boolean isAnswerCorrect(String userAnswer)
{
// compare userAnswer to answer; return true if they are the same
}
}
Now create a GUI frame that creates a question object and asks the question of the user. Call isAnswerCorrect to determine if the answer is correct. If so, call writeCertificate. If not call writeConsolationLetter.
By OTA: Yupei Xiong, PhD
OTA Rating: 4.8/5
Your Price: $2.19 (original value ~$27.93)
What's included:
Page generated in 0.0132 seconds