Emily
December 4th, 2010, 03:14
Download Link: Only the registered members can see the link.
Or:
create packages:
school.math
school.science
school.util
In School.math
create a class called
MathDeclare.java
package school.math;
public class MathDeclare {
/**
* @author Emily
*/
/*
* The number of Correct Answers You Have
*/
public static int scoreCorrect;
/*
* The number of Incorrect Answers You Have
*/
public static int scoreIncorrect;
/*
* The Questions being ask, it is sent as an arrray
* that way we can save space, and make it look good
*/
public static String question [] = {
"Factor (X^2 - 1)",
"Answer this question False",
"One Plus One Equals?",
"Hi",
"Bye",
"LOL",
"Maybe",
"Leave",
"Mean",
"Pie",
"Ask again",
"kk",
};
/*
* The Correct Answer to the question asked, also sent as an array
* so that we can svave space, and make it look good
*/
public static String[] correctAnswer = {
"(X+1)(X-1)",
"False",
"2",
"Hi",
"Bye",
"LOL",
"Maybe",
"Leave",
"Mean",
"Pie",
"Ask again",
"kk",
};
}
And then create another file called
MathQuiz.java
package school.math;
import java.util.Scanner;
import school.util.Misc;
public class MathQuiz {
/**
* @author Emily
*/
public static void main(String args[]) {
Scanner player = new Scanner(System.in);
String Answer;
int random = Misc.random(10);
System.out.println("Question:");
System.out.println(""+MathDeclare.question[random]);
System.out.println("Answer:");
Answer = player.next();
if (Answer.equals(MathDeclare.correctAnswer[random])) {
MathDeclare.scoreCorrect += 1;
System.out.println("Correct!");
} else {
MathDeclare.scoreIncorrect += 1;
System.out.println("Incorrect!");
System.out.println("Correct Answer: "+MathDeclare.correctAnswer[random]);
}
}
}
Now, in school.science
create a class:
ScienceDeclare.java
package school.science;
public class ScienceDeclare {
/**
* @author Emily
*/
public static int scoreCorrect;
public static int scoreIncorrect;
public static String question [] = {
"Answer this question True",
"Answer this question False",
"One Plus One Equals?",
"Hi",
"Bye",
"LOL",
"Maybe",
"Leave",
"Mean",
"Pie",
"Ask again",
"kk",
};
public static String[] correctAnswer = {
"True",
"False",
"2",
"Hi",
"Bye",
"LOL",
"Maybe",
"Leave",
"Mean",
"Pie",
"Ask again",
"kk",
};
}
Now create a file in the same package
ScienceQuiz.java
package school.science;
import java.util.Scanner;
import school.util.Misc;
public class ScienceQuiz {
/**
* @author Emily
*/
public static void main(String args[]) {
Scanner player = new Scanner(System.in);
String Answer;
int random = Misc.random(10);
System.out.println("Question:");
System.out.println(""+ScienceDeclare.question[random]);
System.out.println("Answer:");
Answer = player.next();
if (Answer.equals(ScienceDeclare.correctAnswer[random])) {
ScienceDeclare.scoreCorrect += 1;
System.out.println("Correct!");
} else {
ScienceDeclare.scoreIncorrect += 1;
System.out.println("Incorrect!");
System.out.println("Correct Answer: "+ScienceDeclare.correctAnswer[random]);
}
}
}
Now in school.util create a class:
Misc.java
package school.util;
public class Misc {
/**
* @author Emily
*/
public static int random(int range) {
return (int)(Math.random() * (range + 1));
}
}
Basically uses array for the question, and correct answer, change the
int random = Misc.random(10);
To how ever many of questions you have, it'll randomly select one on startup to ask you.
Credits:
Emily
You can use this if you want, or improve it, i could care less. I just thought of the idea after a nap so i decided to make it quick.
Rate/Hate/Comment
Or:
create packages:
school.math
school.science
school.util
In School.math
create a class called
MathDeclare.java
package school.math;
public class MathDeclare {
/**
* @author Emily
*/
/*
* The number of Correct Answers You Have
*/
public static int scoreCorrect;
/*
* The number of Incorrect Answers You Have
*/
public static int scoreIncorrect;
/*
* The Questions being ask, it is sent as an arrray
* that way we can save space, and make it look good
*/
public static String question [] = {
"Factor (X^2 - 1)",
"Answer this question False",
"One Plus One Equals?",
"Hi",
"Bye",
"LOL",
"Maybe",
"Leave",
"Mean",
"Pie",
"Ask again",
"kk",
};
/*
* The Correct Answer to the question asked, also sent as an array
* so that we can svave space, and make it look good
*/
public static String[] correctAnswer = {
"(X+1)(X-1)",
"False",
"2",
"Hi",
"Bye",
"LOL",
"Maybe",
"Leave",
"Mean",
"Pie",
"Ask again",
"kk",
};
}
And then create another file called
MathQuiz.java
package school.math;
import java.util.Scanner;
import school.util.Misc;
public class MathQuiz {
/**
* @author Emily
*/
public static void main(String args[]) {
Scanner player = new Scanner(System.in);
String Answer;
int random = Misc.random(10);
System.out.println("Question:");
System.out.println(""+MathDeclare.question[random]);
System.out.println("Answer:");
Answer = player.next();
if (Answer.equals(MathDeclare.correctAnswer[random])) {
MathDeclare.scoreCorrect += 1;
System.out.println("Correct!");
} else {
MathDeclare.scoreIncorrect += 1;
System.out.println("Incorrect!");
System.out.println("Correct Answer: "+MathDeclare.correctAnswer[random]);
}
}
}
Now, in school.science
create a class:
ScienceDeclare.java
package school.science;
public class ScienceDeclare {
/**
* @author Emily
*/
public static int scoreCorrect;
public static int scoreIncorrect;
public static String question [] = {
"Answer this question True",
"Answer this question False",
"One Plus One Equals?",
"Hi",
"Bye",
"LOL",
"Maybe",
"Leave",
"Mean",
"Pie",
"Ask again",
"kk",
};
public static String[] correctAnswer = {
"True",
"False",
"2",
"Hi",
"Bye",
"LOL",
"Maybe",
"Leave",
"Mean",
"Pie",
"Ask again",
"kk",
};
}
Now create a file in the same package
ScienceQuiz.java
package school.science;
import java.util.Scanner;
import school.util.Misc;
public class ScienceQuiz {
/**
* @author Emily
*/
public static void main(String args[]) {
Scanner player = new Scanner(System.in);
String Answer;
int random = Misc.random(10);
System.out.println("Question:");
System.out.println(""+ScienceDeclare.question[random]);
System.out.println("Answer:");
Answer = player.next();
if (Answer.equals(ScienceDeclare.correctAnswer[random])) {
ScienceDeclare.scoreCorrect += 1;
System.out.println("Correct!");
} else {
ScienceDeclare.scoreIncorrect += 1;
System.out.println("Incorrect!");
System.out.println("Correct Answer: "+ScienceDeclare.correctAnswer[random]);
}
}
}
Now in school.util create a class:
Misc.java
package school.util;
public class Misc {
/**
* @author Emily
*/
public static int random(int range) {
return (int)(Math.random() * (range + 1));
}
}
Basically uses array for the question, and correct answer, change the
int random = Misc.random(10);
To how ever many of questions you have, it'll randomly select one on startup to ask you.
Credits:
Emily
You can use this if you want, or improve it, i could care less. I just thought of the idea after a nap so i decided to make it quick.
Rate/Hate/Comment