Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners java collections
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


sasikumar
java collections
1 Answer(s)      4 years and 6 months ago
Posted in : Java Beginners


i need a sample quiz program by using collections and its property reply soon as possible ....

Advertisement
View Answers

April 7, 2010 at 2:50 PM


Hi Friend,

Try the following code:

import java.io.*;
import java.util.*;

class Test {
String question;
String ans;
String op1;
String op2;
String op3;
String op4;

Test(String question, String ans, String op1, String op2, String op3,
String op4) {
this.question = question;
this.ans = ans;
this.op1 = op1;
this.op2 = op2;
this.op3 = op3;
this.op4 = op4;
}

public String getQuestion() {
return question;
}

public String getAns() {
return ans;
}

public String getOp1() {
return op1;
}

public String getOp2() {
return op2;
}

public String getOp3() {
return op3;
}

public String getOp4() {
return op4;
}
}

public class AskQuestions {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int count = 0;
int i = 0;
ArrayList<Test> list = new ArrayList<Test>();
list.add(new Test("Where is Taj Mahal", "Agra", "Mumbai", "Delhi",
"Mathura", "Agra"));
list.add(new Test("Where is Red Fort", "Delhi", "Mumbai", "Delhi",
"Amritsar", "Agra"));
list.add(new Test("Where is Golden Temple", "Amritsar", "Mumbai",
"Delhi", "Amritsar", "Agra"));
list.add(new Test("Where is Eiffel Tower", "Paris", "New York",
"Sydney", "Washington", "Paris"));
list.add(new Test("Where is Statue of Liberty", "New York", "New York",
"Sydney", "Washington", "Paris"));
for (Test s : list) {
i = i + 1;
System.out.println("Question" + i + " " + s.getQuestion());
System.out.println();
System.out.println("Option 1 " + s.getOp1());
System.out.println("Option 2 " + s.getOp2());
System.out.println("Option 3 " + s.getOp3());
System.out.println("Option 4 " + s.getOp4());
System.out.println();
System.out.print("Your Answer: ");
String answer = input.nextLine();
if (answer.equals(s.getAns())) {
count = count + 2;
}
System.out.println("Correct Answer: " + s.getAns());
System.out.println();
}
System.out.println("Your result is: " + count + "/10");
}
}

Hope that it will be helpful for you.

Thanks


Related Tutorials/Questions & Answers:
java collections
java collections  what are all the methods and things added for collections in java5 and java6 please kindly reply me as soon as possible
Collections in Java
Collections in Java  What is Concurrent Hash map
Advertisements
Collections in Java
Collections in Java  What is Concurrent Hash map
java collections
java collections  Dear Friends plz help me to complete this program import java.util.*; public class StringDemo { static String a="{a=100;b=200;c=300... achieve this plz without using stringtokenizer with any collections!!!  
collections in java
collections in java  please explain me the flow of this program..i m getting o/p as 2 1 1..y not 2 1 0..is it that if we change the i2 value,it doesnt remove. import java.util.*; public class Mapit { public static void main
collections - Java Interview Questions
collections  The Java Collections API  Hi friend, Java Collections of API (Application Programming Intreface) Consists of several... information on Java Collection API visit to : http://www.roseindia.net
java Collections - Java Beginners
java Collections   HI Friends, I want to pick a random element from a set.How can i achieve this.I have a set of objects , I want to pick a random object every time from the set..  Hi Friend, Try
wt are the collections in java
wt are the collections in java  plese send me the reply   Hi Friend, Java Collections API (Application Programming Interface) Consists... tool to the creation of custom data structures. For more information on Java
collections - Java Interview Questions
collections   what is the way to insert map values into a set in collections
Collections
/java/jdk6/introduction-collections-api.shtml http://www.roseindia.net/javacodeexamples/index.shtml http://www.devmanuals.com/tutorials/java/collections/index.html...Collections  Hi, Please send a study material on collections
java collections - Java Beginners
java collections  i need a sample quiz program by using collections and its property reply soon as possible ....   Hi Friend, Try the following code: import java.io.*; import java.util.*; class Test { String
Collections - Java Beginners
Collections  I want to know about the new for loop used in collections... can anyone explain in short..? If possible can you give some sites..., http://www.roseindia.net/java/jdk6/introduction-collections-api.shtml
collections in java - Java Interview Questions
collections in java  What is collection
collections - Java Interview Questions
in Array of type Integer. Collections : ArrayList al = new ArrayList
java collections - Java Beginners
java collections  Object o1=new Object("hello"); Object o2=new Object("hello"); is hashmap add these objects?  Hi Friend, The constructor of Object class doesn't contains any parameter. IF you want to any object
Collections in Java
Collections in Java are data-structures primarily defined through a set of classes and interface and used by Java professionals. Some collections in Java that are defined in Java collection framework are: Vectors, ArrayList, HashMap
collections
collections  why we need collections.when we will use collections in our applications
collections
collections  in collections can we perform binarysearch on arraylist elements without sorting them
Collections arraylist - Java Interview Questions
Collections arraylist  how we can make array list as syncronised....and what will be the code for that?  Hi Friend, Try the following code: import java.util.*; class SynchronizedArrayList{ public static void
Java Collections - Java Interview Questions
Java Collections  Hi, can anybody tell me, Using which collection we can get the data of an employee from the Emp table when the value of the column... to : http://roseindia.net/java/collection/collection-get-column.shtml Thanks
core Java Collections - Java Beginners
core Java Collections   what is Vector? send me any example what is differece between Array and Vector? Why Vector is called Sychronized?  Hi Friend, The Vector implements a growable array of objects
Java Collections - Design concepts & design patterns
Java Collections  I am designing an application where the program is meant to read from 2 different text files (eg FileA and FileB) containing so many Long numbers (e.g 4 million numbers in each file). The application is meant
Java Collections - Design concepts & design patterns
Java Collections  I am designing an application where the program is meant to read from 2 different text files (eg FileA and FileB) containing so many Long numbers (e.g 4 million numbers in each file). The application is meant
what is collections?
what is collections?  what is collections
Working with java Collections class
Working with java Collections class   ... with Collections class of java.util package. Actually java collections framework... of Collections class. For example- add element, copy elements, reverse data
Collections API
Collections API  hello, What is the Collections API?   hi The Collections API is a set of classes and interfaces that support operations on collections of objects
Hibernate Criteria With Collections Example
Hibernate Criteria With Collections Example  Good code of Hibernate Criteria With Collections Example. Thanks   Example program of using Hibernate Criteria With Collections in your Java project. Check the tutorial
Advertisements
 

 

 

DMCA.com