I have a created a similar application long back using Java, resource properties, check the following classes
- RandomComaprator.java
- RandomInt.java
- RandonQuestions.java
- TestQuestions.java
- questions.properties
Here are the five classes that i have created, when you run this program
RandonQuestions.java
All the questions will be picked randomly from the properties files and display it to the users,
The qusetions in the properties can be converted to the quiz kind of questions
RandomComparator.java
public class RandomComparator implements Comparator {
Random random = new Random();
public int compare(Integer arg0, Integer arg1) {
return random.nextInt() - random.nextInt();
}
}
RandomInt.java
public class RandomInt {
/**
* @param args
*/
public static void main(String[] args) {
RandomInt int1 = new RandomInt();
Set<Integer> s = new HashSet<Integer>();
//System.out.println(s);
//System.out.println(int1.randomSet(s, 2, 1));
System.out.println(int1.randamPriorityQueue(s, 5, 2));
}
private Set<Integer> randomSet(Set<Integer> randomNumbers, int totalQuestions,
int numOfQuestionToDisplay) {
while (randomNumbers.size() < numOfQuestionToDisplay) {
Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(totalQuestions);
randomNumbers.add(randomInt);
}
return randomNumbers;
}
private Set<Integer> randamPriorityQueue(Set<Integer> randomNumbers, int totalQuestions,
int numOfQuestionToDisplay) {
PriorityQueue<Integer> queue = new PriorityQueue<Integer>(
totalQuestions, new RandomComparator());
for (int i = 0; i < totalQuestions; i++) {
queue.add(i);
}
Iterator<Integer> iterator = queue.iterator();
for (int i = 0; i < numOfQuestionToDisplay && iterator.hasNext(); i++) {
randomNumbers.add(iterator.next());
}
return randomNumbers;
}
private Set<Integer> randomSet(Set<Integer> randomNumbers) {
if (randomNumbers.size() == 2) {
return randomNumbers;
}
Random randomGenerator = new Random();
for (int i = 0; i < 2; i++) {
int randomInt = randomGenerator.nextInt(4);
System.out.println("Generated : " + randomInt);
System.out.println(randomNumbers + " " + randomNumbers.size());
if (randomNumbers.size() == 2) {
return randomNumbers;
}
randomNumbers.add(randomInt);
randomSet(randomNumbers);
}
return randomNumbers;
}
}
TestQuestions.java
public class TestQuestions {
private static ResourceBundle s_rb;
private static TestQuestions s_questions;
/**
* Private Constructor
*/
private TestQuestions()
{
s_rb = ResourceBundle.getBundle("org.com.questions");
}
/**
* static method to get the singleton instance
*/
public static TestQuestions getInstance()
{
if(s_questions == null)
s_questions = new TestQuestions();
return s_questions;
}
/**
* Get the ResourceBundle
*/
public final ResourceBundle getBundle()
{
return s_rb;
}
/**
* Get the String
*/
public final String getString(String key)
{
return s_rb.getString(key);
}
}
Following is the questions.properties
0=What is the difference between an Interface and an Abstract class?
1=What is the purpose of garbage collection in Java, and when is it used?
2=Describe synchronization in respect to multithreading?
3=Explain different way of using thread?
4=What are pass by reference and passby value?
5=What is HashMap and Map?
6=Difference between HashMap and HashTable?
7=Difference between Vector and ArrayList?
8=Difference between Swing and Awt?
9=What is the difference between a constructor and a method?
10=What is an Iterator?
11=State the significance of public, private, protected, default ?
12=What is an abstract class?
13=What is static in java?
14=What is final?
15=What releases of Java technology are currently available? What do they contain?
16=What platforms is the JDK software available on?
17=Should I use the Production Release or Reference Implementation of the Solaris JDK software and JRE?
18=What about a version for my favorite platform? When can I get it?
19=How do I download Java technology and/or JDK software? How do I install it?
20=Where can I find information about HotJava?
21=How can I get started with programming in Java?
22=Do I need special server software to use applets?
23=Who is licensing Java technology?
24=Is JavaScript available? How do I find out more about it?
25=What are the security problems I've heard about JavaScript scripts?
26=I can't find the API documentation on any classes in the sun.* packages.
27=Why developers should not write programs that call 'sun' packages
28=Where can I get the Java programming language source code?
29=What is the Java Version/Naming convention?
30=What is the difference between a constructor and a method?
RandonQuestions.java
public class RandonQuestions {
/**
* Display the questions.
*/
public void getQuestions() {
String s = "";
StringBuilder sb = new StringBuilder(s);
int quest[] = getNumberOfQuestions();
for (int i = 0; i < quest.length; i++) {
String key = "" + quest[i] + "";
sb.append(i + 1 + "" + ". ");
sb.append(TestQuestions.getInstance().getBundle().getString(key)
+ "\n");
}
System.out.println(sb);
}
/**
* @return int array
*/
public int[] getNumberOfQuestions() {
PriorityQueue<Integer> pq;
Random rm;
int a = 5;
int ar[] = new int[5];
pq = new PriorityQueue<Integer>(a, new Comparator<Integer>() {
public int compare(Integer i, Integer j) {
int result = i % 2 - j % 2;
if (result == 0)
result = i - j;
return result;
}
});
rm = new Random();
for (int i = 0; i < a; i++) {
int number = rm.nextInt(30);
pq.offer(number);
}
for (int i = 0; i < a; i++) {
ar[i] = pq.poll();
}
return ar;
}
/**
* @param args
*/
public static void main(String[] args) {
RandonQuestions obj = new RandonQuestions();
obj.getQuestions();
}
}
Put all the files in the folder and execute, this will create a proejct what you are looking for