Methods in Java 1 Answer(s) 3 years and 6 months ago
Posted in : Java Beginners
View Answers
November 23, 2009 at 11:52 AM
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); } }
Thanks
Related Pages:
Java methods Java methods What are the differences between == and .equals
native methods
native methods what is native methods in java?
A native method is a method that is implemented in a language other than Java.
The Java... into Java. To use Java as a scientific and high performance language, when
Java overloaded methods Java overloaded methods Can overloaded methods can also be overridden
Functions and Methods
Functions and Methods (1) Write a program in java to input 10... in java to input day number. Use a function daysofweek(int dysno) to accept... to print the corresponding day of the week.
(3) Write a Java program to input
Functions and Methods
Functions and Methods Write a Java program to input the sides of a triangle. Pass the sides to a function decide(int x,int y,int z) which checks and prints whether the triangle is equilateral,isosceles or scalene.
 
Overriding methods
Overriding methods How to use overriding method in the java progrem?
The overriding method are define in the subclass that has same name,same argument and same return type as a method in the superclass.
class Animal
java object class methods java object class methods What are the methods in Object class? There are lots of methods in object class.
the list of some methods are as-
clone
equals
wait
finalize
getClass
hashCode
notify
notifyAll
factory methods in java?
factory methods in java? what are factory methods in java?
Hi Friend,
Factory methods are static methods that return an instance of the native class like Pattern.compile(), Calendar.getInstance
abstract methods in java
abstract methods in java what is abstract methods in java.give better examples for understanding
Hi Friend,
Please visit the following link:
http://www.roseindia.net/java/master-java/abstract-class.shtml
Thanks
to create a java class and methods
to create a java class and methods How to create a java class... it with methods that can be used to reverse a list & append two lists.Also to comment on whether the dsign ade has led to make methods for append
Final Methods - Java Tutorials
The final Keyword in Java
In Java, final keyword is applied in various context. The final
keyword is a modifier means the final class can't be extended... methods
The final method can be declare as follows:
public final String
java methods - Java Beginners java methods Hello,
what is difference between a.length() and a.length;
kindly can anybody explain.
thanks for your time Hi Friend,
length() is used to find the length of string whereas length is used
Methods in Java - Java Beginners Methods in Java Hello.
Currently i am involved in a group project and we have each been given a specific part of code to create our joint programI however have been given the job to create a method for storing and recalling 5
Overloaded methods - Java Beginners
Overloaded methods Write two overloaded methods that return the average of an array with the following headers:
a) public static int average(int[] array)
b) public static double average(double[] array)
Hi Friend
java methods - Java Interview Questions java methods what are native methods? how and when they are use? Hi friend,
The ability to write just one set of code in Java... C code into your Java application.
The steps to creating native methods
list of predeined methods and use java
list of predeined methods and use java I need list of predefined methods in java like reverse,compare,tostring, etc
Callback Methods
Callback Methods
Callbacks methods are the way of managing life cycle of
an instance. Callback methods are generally used by containers. The methods are
called at specific time
Methods - OOP Java NotesMethods - OOP
Static methods
If your method doesn't use... utility methods
and main(...), you should probably not be using static methods.
A good example of a static methods in Java is the Math or Character
java file with many methods - Ajax java file with many methods I have to send response to a java file where there are many methods and I have to call one of them by passing parameter .How can I do
What are the methods in Object? - Java Beginners
What are the methods in Object? Hi,
What are the methods in Object? Give example of methods in Object.
Thanks
Hello,
There are lot of method in object class some of are as follows
toString();
wait
methods in the applet - Applet methods in the applet import java.awt.*;
import java.applet.Applet...(Graphics g)
{
g.drawString(m,10,10);
}
}
The init() method used in the java applet is simular to the contructor defined in a java application. The purpose
Java Methods Problem - Java Beginners JavaMethods Problem I have to write a program that has three types of pie. Apple, which is the default pie, cherry and pumpkin. I then have to ask the customer what type of pie they like and store it in kind and then ask
Java Methods Problem - Java Beginners JavaMethods Problem I have to write a program that has three types of pie. Apple, which is the default pie, cherry and pumpkin. I then have to ask the customer what type of pie they like and store it in kind and then ask
Java :Thread Methods Java :Thread Methods
This section explains methods of Thread class.
Thread Methods :
Thread class provides many method to handle different thread... and allow other
threads the temporal executing thread object.
Some other methods
methods
methods PrintStream class has two formatting methods,what
methods
methods PrintStream class has two formatting methods,what
methods
methods PrintStream class has two formatting methods,what
Non-virtual Methods in Java - java tutorials
: #000000;
}
Non Virtual Methods in Java
Lets see the concept of virtual methods, a virtual function is
function whose behavior can not be overridden... hierarchy.
In Java programming language all the methods are virtual, i.e.
notify and notifyAll methods - Java Beginners
notify and notifyAll methods I need a program demonstrating the methods of notify and notifyAll. please can you suggest me a way out. visit this link
http://www.java-samples.com/showtutorial.php?tutorialid=306
methods and access specifiers in java - Java Beginners methods and access specifiers in java i am a java beginner..give me the rules f methods and access specifiers Hi friend,
visit for more information:
http://www.roseindia.net/java/
http://www.roseindia.net
RIAs Methods And Techniques
RIAs Methods And Techniques
JavaScript
It is the first major client side...-side solution. Ajax,
the advance tool of Java Script becomes more prominent... of Java and the JVM are available in the
RIA developing world. These are: Curl
Abstract class,Abstract methods and classes
Abstract methods and classes
While going through the java language programming you have learned so many
times the word abstract. In java programming language the word abstract
Static/Class methods Java NotesStatic/Class methods
There are two types of methods.
Instance methods are associated with an object and
use the instance variables of that object.
This is the default.
Static methods use no instance
Object Class Methods in Java
We are going to discus about Object Class Methods in Java. The
java.lang.Object class is the root of the class hierarchy tree in
JDE(java development...(), wait(), etc
Java object class methods are:-
finalize()
clone()
equals
stateless session bean with methods error - Java Beginners
stateless session bean with methods error I have to create stateless session bean with 3 methods and then create a servlet which remotely calls all three methods in that session bean. I have 4 files created-index.jsp under web
Object-Oriented Implementation of Numerical Methods - Java Tutorials
Object-Oriented Implementation of Numerical Methods
2002-04-01 The Java... of Numerical Methods
Author:
Dr. Heinz M. Kabutz
If you are reading... of The Java(tm) Specialists'
Newsletter, sent to 3101 (!) Java experts in over
Java Methods JavaMethods
 ... and the usage of methods in Java is to access a single method either on class....
In Java, java.lang.reflect.*; package
Abstract methods and classes
Abstract methods and classes
While going through the java language programming you have learned so many
times the word abstract. In java programming language the word abstract
Common Component Methods
getX(), getY(), getWidth(), and getHeight() methods while
working on Java 2...() methods
to directly access the width and height while working on Java 2...
Common Component Methods
 
Methods - Introduction Java NotesMethods - Introduction
Method = Function = Procedure...
and is used in Java. Every programmer has this idea, but sometimes uses....
Why use methods?
For reusable code
If you need
core java ,io operation,calling methods using switch cases
core java ,io operation,calling methods using switch cases How to create a dictionary program,providing user inputs using io operations with switch cases and providing different options for searching,editing,storing meanings
Summary: Methods Java: Summary: Methods
Parameters
Method parameters are separated by commas.
Parameters are converted to these larger or equal types (int, long... void main(String[] args)
signature
To decide which method to call, Java looks