Remember when I said I had most of the code done?
Turns out I'm an idiot and had 2 separate programs in one. In my mind, the Questionaire-O-Matic program was the same as the Questionaire-O-Creator program.
Oh, spagueti, oh.
Big fuck up there.
But never fear, my fellow maggots!
I'm totally gonna fix that.
And I'll post it the code here, then figure out how to do the graphical interface and presto!
The end of times will be upon us.
I'm stretching what little I know about java to do this, so, please, don't laugh too hard when seeing the code.
It may be pernicious to your health.
The code will be done in 6-7 hours, tops. //EDIT: (hahahhahaha, no. Fell asleep)
No it won't.
Yes it will!
Nope.
Shut up and write the goddamn code, you slut.
Ok.
EDIT 1:
I'm doing 35 questions. Less than that and it's too short, and more would be tedious to answer.
EDIT 2:
This is what I have so far:
(this is the class I'll use for the questions)
Code: Select all
public class triviaQuestion_N {
/**instance variables:**/
String questionN;
String answerA;
String answerB;
String answerC;
String answerD;
boolean a, b, c, d;
int correctAnswer;
int levelOfDifficulty;
// question: Why am I always told that I should make these private?
public triviaQuestion_N(String N, String A, String B, String C, String D, int value, int easy_hard){
/**constructor:**/
questionN = N;
answerA = A;
answerB = B;
answerC = C;
answerD = D;
levelOfDifficulty = easy_hard;
a = b = c = d = false;
if (value == 1){
a= true;
}//if user selects alternative 1 as the correct one
else {if(value == 2){
b= true;
}//if user selects alternative 2 as the correct one
else {if(value == 3){
c= true;
}//if user selects alternative 3 as the correct one
else {if(value == 4){
d= true;
}//if user selects alternative 4 as the correct one}
}//else 3
}//else 2
}//else 1
}//constructor
public void TheCorrectAnsweris (){
if (a==true){
System.out.print(a);
}//if1
if (b==true){
System.out.print(b);
}//if2
if (c==true){
System.out.print(c);
}//if3
if (d==true){
System.out.print(d);
}//if3
}//TheCorrectAnsweris method
}//class
(This is the class I'll use to create the questionaire)
Code: Select all
public class Questionaire_O_Maker {
public triviaQuestion_N[] excelent;
public triviaQuestion_N[] competent;
public triviaQuestion_N[] defficient;
public triviaQuestion_N[] functionallyRetarded;
public int numberOfQuestions;
public Questionaire_O_Maker (int questionNumber){
numberOfQuestions= questionNumber;
}//constructor
public void Create_Questionaire(){
excelent = competent = defficient = functionallyRetarded = new triviaQuestion_N[numberOfQuestions];
for (int questionsWrittenSoFar=0; questionsWrittenSoFar<=numberOfQuestions; questionsWrittenSoFar++){
excelent = new triviaQuestion_N [questionsWrittenSoFar];
competent = new triviaQuestion_N [questionsWrittenSoFar];
defficient = new triviaQuestion_N [questionsWrittenSoFar];
excelent = new triviaQuestion_N [questionsWrittenSoFar];
functionallyRetarded = new triviaQuestion_N [questionsWrittenSoFar];
}//for
System.out.print("Done with the questions!");
}//method
}//class
The whole 'assign each individual question to a particular array according to difficulty' concept kinda went out the window.
Probably going to incorporate it later.
Ok, gotta keep going.
EDIT3: Fuck! I screwed big time.
EDIT4: Ok, I fixed the problem.
Man, arrays are difficult to manage.
Here's the fixed version:
Code: Select all
import IIC1103Package.Usuario;
public class Questionaire_O_Maker {
public triviaQuestion_N[] excelent;
public triviaQuestion_N[] competent;
public triviaQuestion_N[] defficient;
public triviaQuestion_N[] functionallyRetarded;
public int numberOfQuestions;
public Questionaire_O_Maker (int questionNumber){
questionNumber= Usuario.entero("Enter the desired number of questions");
numberOfQuestions= questionNumber;
}//constructor
public void Create_Questionaire(){
excelent = competent = defficient = functionallyRetarded = new triviaQuestion_N[numberOfQuestions];
for (int questionsWrittenSoFar=0; questionsWrittenSoFar<numberOfQuestions; questionsWrittenSoFar++){
excelent [questionsWrittenSoFar] = new triviaQuestion_N();
Usuario.mensaje(questionsWrittenSoFar+1);
}//for1
Usuario.mensaje("Questions of difficulty 4 are done!");
for (int questionsWrittenSoFar=0; questionsWrittenSoFar<=numberOfQuestions; questionsWrittenSoFar++){
competent [questionsWrittenSoFar]= new triviaQuestion_N() ;
Usuario.mensaje(questionsWrittenSoFar+1);
}//for2
Usuario.mensaje("Questions of difficulty 3 are done!");
for (int questionsWrittenSoFar=0; questionsWrittenSoFar<=numberOfQuestions; questionsWrittenSoFar++){
defficient [questionsWrittenSoFar]= new triviaQuestion_N();
Usuario.mensaje(questionsWrittenSoFar+1);
}//for3
Usuario.mensaje("Questions of difficulty 2 are done!");
for (int questionsWrittenSoFar=0; questionsWrittenSoFar<=numberOfQuestions; questionsWrittenSoFar++){
functionallyRetarded [questionsWrittenSoFar]= new triviaQuestion_N();
Usuario.mensaje(questionsWrittenSoFar+1);
}//for4
Usuario.mensaje("Questions of difficulty 1 are done!");
System.out.print("Done with the questions!");
}//method
}//class
Sorry if it seems awfully inefficient, I'm going to try to fix that once the damn thing works.
Which reminds me of a cool thing I once read about engineering: That you're finished not when there's nothing to add, but when there's nothing to take away.
EDIT 5: I just realized I've been making a program in which none of the questions is saved for more than one run. Screw this, I'm just going to make a program specially for Berserk, and then write a more general form, once I figure out how to save the values I assign to objects.
EDIT 6: Does anyone know where I can get the API needed for serialization?
If I understand what I read online correctly, that application would allow me to save the value of the objects I create with the Questionaire-O-Maker, which I could use as input for the quiz program.
And the Berserk quiz would be my first.
I'm saving myself for it.
EDIT 7: It was part of the core package. Dur. Proceeding to figure out how it works.
EDIT 8 and final:
This is the last edit of the day. It's late and I've got other things to do.
Can't say I'm satisfied with what I managed to do, but it's something.
Here's what I believe is the final code for the Questions and Trivia-Builder programs:
[spoiler]
Code: Select all
import IIC1103Package.Usuario;
import java.io.Serializable;
public class triviaQuestion_N implements Serializable{ [b]//makes the class serializable, which is kind of important later on.
/**instance variables:**/[/b]
String questionN;
String answer1;
String answer2;
String answer3;
String answer4;
boolean a, b, c, d;
int correctAnswer;
int levelOfDifficulty;
[b] // question: Why am I always told that I should make these private?[/b]
public triviaQuestion_N(){
[b]/**constructor:**/[/b]
questionN= Usuario.texto("Write question here");
answer1= Usuario.texto("Write answer 1 here");
answer2= Usuario.texto("Write answer 2 here");
answer3= Usuario.texto("Write answer 3 here");
answer4= Usuario.texto("Write answer 4 here");
correctAnswer= Usuario.entero("What is the correct answer?)");
a = b = c = d = false;
if (correctAnswer == 1){
a= true;
}[b]//if user selects alternative 1 as the correct one[/b]
else {if(correctAnswer== 2){
b= true;
}[b]//if user selects alternative 2 as the correct one[/b]
else {if(correctAnswer == 3){
c= true;
}[b]//if user selects alternative 3 as the correct one[/b]
else {if(correctAnswer == 4){
d= true;
}[b]//if user selects alternative 4 as the correct one}[/b]
}[b]//else 3[/b]
}[b]//else 2
}//else 1
}//constructor[/b]
public void TheCorrectAnsweris (){
if (a==true){
System.out.print(a);
}[b]//if1 [/b]
if (b==true){
System.out.print(b);
}[b]//if2 [/b]
if (c==true){
System.out.print(c);
}[b]//if3 [/b]
if (d==true){
System.out.print(d);
}[b]//if3[/b]
}//TheCorrectAnsweris method
public void TheQuestionis (){
System.out.print(questionN);
}[b]//Method to print out the question being asked.[/b]
public void ThePossibleAnswersare(){
System.out.println("A) "+ answer1);
System.out.println("B) "+ answer2);
System.out.println("C) "+ answer3);
System.out.println("D) "+ answer4);
}[b]//method to tell you what the alternatives are.[/b]
}[b]//class[/b]
[/spoiler]
[spoiler]
Code: Select all
import IIC1103Package.Usuario;
import java.io.Serializable;
import java.io.ObjectOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class Questionaire_O_Maker implements Serializable { [b]//makes the program serializable, which allows the user to save the questions/answers he/she writes[/b]
public triviaQuestion_N[] excelent;
public triviaQuestion_N[] competent;
public triviaQuestion_N[] defficient;
public triviaQuestion_N[] functionallyRetarded;
public int numberOfQuestions;
public Questionaire_O_Maker (){
numberOfQuestions= Usuario.entero("Enter the desired number of questions");
excelent = competent = defficient = functionallyRetarded = new triviaQuestion_N[numberOfQuestions];
for (int questionsWrittenSoFar=0; questionsWrittenSoFar<numberOfQuestions; questionsWrittenSoFar++){
excelent [questionsWrittenSoFar] = new triviaQuestion_N();
Usuario.mensaje(questionsWrittenSoFar+1);
}[b]//for1 forces a discrete number of iterations, making an array of trivia questions in the process. This array contains all ridiculously difficult questions [/b]
Usuario.mensaje("Questions of difficulty 4 are done!");
for (int questionsWrittenSoFar=0; questionsWrittenSoFar<numberOfQuestions; questionsWrittenSoFar++){
competent [questionsWrittenSoFar]= new triviaQuestion_N() ;
Usuario.mensaje(questionsWrittenSoFar+1);
}[b]//for2 forces a discrete number of iterations, making an array of trivia questions in the process. This array contains all moderately difficult questions [/b]
Usuario.mensaje("Questions of difficulty 3 are done!");
for (int questionsWrittenSoFar=0; questionsWrittenSoFar<numberOfQuestions; questionsWrittenSoFar++){
defficient [questionsWrittenSoFar]= new triviaQuestion_N();
Usuario.mensaje(questionsWrittenSoFar+1);
}[b]//for3 forces a discrete number of iterations, making an array of trivia questions in the process. This array contains all normal questions [/b]
Usuario.mensaje("Questions of difficulty 2 are done!");
for (int questionsWrittenSoFar=0; questionsWrittenSoFar<numberOfQuestions; questionsWrittenSoFar++){
functionallyRetarded [questionsWrittenSoFar]= new triviaQuestion_N();
Usuario.mensaje(questionsWrittenSoFar+1);
}[b]//for4 forces a discrete number of iterations, making an array of trivia questions in the process. This array contains all easy questions [/b]
Usuario.mensaje("Questions of difficulty 1 are done!");
System.out.print("Done with the questions!");
}//constructor
public static void main(String[] args) {
Usuario.mensaje("Introduction to Quiz-writing program"); [b]//Here you write whatever inane bullshit you'll greet the user with.[/b]
Usuario.mensaje("Instructions"); [b]//pretty much self-explanatory[/b]
Questionaire_O_Maker writeNameOfQuestionaireHere = new Questionaire_O_Maker();[b]// I'll change this part so the user can decide on the name of the questionaire [/b]
try{
FileOutputStream filestream = new FileOutputStream ("writeNameOfQuestionaireHere.ser");
ObjectOutputStream os = new ObjectOutputStream (filestream);
os.writeObject(writeNameOfQuestionaireHere);
os.close();[b]// these 3 lines save all info pertaining to the objects created when this program was executed. [/b]
}
catch(IOException ex){
ex.printStackTrace();
}//catch exceptions
}//main
}//Questionaire_O_Maker class
[/spoiler]
And here the actual Trivia program, where I've been stuck for the last couple of hours.
[spoiler]
Code: Select all
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import IIC1103Package.Usuario;
public class Questionaire_O_Matic {
public static void main(String[] args) {
try{
ObjectInputStream os = new ObjectInputStream (new FileInputStream ("writeNameOfQuestionaireHere.ser"));
Questionaire_O_Maker Trivia = (Questionaire_O_Maker) os.readObject();} [b]//this restores the values of the questionaire you made (or someone else made and unploaded to some random forum) and makes a new set of objects out of them, the ones that will be used throughout the program.[/b]
catch(IOException ex){
ex.printStackTrace();
}//catch exceptions
catch (ClassNotFoundException e) {
e.printStackTrace();
}
Usuario.mensaje("Introduction to Trivia"); //Here you write whatever inane bullshit you'll greet the user with.
Usuario.mensaje("Instructions"); //pretty much self-explanatory
excelent[1].theCorrectAnsweris();
[b]And this is where I'm stuck. I have no idea why is it that I get a message telling me that whatever object I use from the file is an invalid variable. I know the values are being loaded, but I can't use them. It's very frustrating. [/b]
[/spoiler]
And that's that.
Hail Satan.