Can't seem to figure how to even get started on writing my code..
I am in an Intermediate Progamming with Java class and I'm having a lot of trouble on figuring out this assignment. Here is the idea..
In this assignment I have to implement a simple multiple choice quiz, using good object-oriented programming style. The user will be shown some questions that he/she will answer. After completing all of the questions, the user will find out how many he/she got right and wrong. He/she will also then be shown the correct answers and the average scores for all users, followed by a sorted list of questions.
The program must read a number of questions from a text file (which I have created) and each question consists of:
1) The question itself, in sentence on a single line.
2) An integer, N, indicating how many answers the question has(one line)
3) The actual N answers, 1 per line
4) An integer, K indicating which answer is correct(single line)
5) An integer, T indicating how many times the question was tried(1 line)
6) An integer, C indicating how many times it was answered correctly(1line)
Here is my Main Class code...
Code:
import java.util.*;
import java.util.Scanner;
import java.IO.*;
public class Assign {
public static void main(String[] args) {
Question [] theQs;
final int numLines = 46;
int index = 0;
File qFile = new File("questions.txt");
Scanner scan = new Scanner(qFile);
theQs = new Question[numLines];
while (scan.hasNext() && index < theQs.length){
theQs[index] = new Question();
theQs[index].getData(qFile);
index++;
}
Here is my Question Class...
Code:
import java.IO.*;
import java.util.*;
import java.util.Scanner;
public class Question {
private String question;
private String [] answers;
private int correctA;
private int numTries;
private int numCorrect;
public Question (String Q, int corA, int numT, int numC, String[] ans) {
}
and here is my textfile with the Questions
Code:
5
Who is the captain of the Pittsburgh Penguins?
4
Evgeni Malkin
Jordan Stall
Sidney Crosby
Pascal Dupuis
2
0
0
How many Stanley Cups have the Pittsburgh Penguins won?
5
One
Two
Three
Four
Five
2
0
0
Who is the quarterback of the Pittsburgh Steelers?
3
Ben Roethlisburger
Hines Ward
James Harrison
0
0
0
How many Super Bowls have the Pittsburgh Steelers won?
6
One
Two
Three
Four
Five
Six
5
0
0
How many national championships has PITT football won?
2
Seven
Nine
1
0
0