Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

Fresher Job


 

Search Host

Monthly Fee($)
Disk Space (MB)
Register With us for Newsletter!
Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Have tutorials?
Add your tutorial to our Java Resource and get tons of hits.

We offer free hosting for your tutorials. and exposure for thousands of readers. drop a mail
roseindia_net@yahoo.com
 
   

Tutorials

Java Server Pages

JAXB

Java Beans

JDBC

MySQL

Java Servlets

Struts

Bioinformatics

Java Code Examples

Interview Questions

 
Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

Web Promotion

Web Submission

Submit Sites

Manual Submission?

Web Promotion Guide

Hosting Companies

Web Hosting Guide

Web Hosting

Linux

Beginner Guide to Linux Server

Frameworks

Persistence Framework

Web Frameworks

Free EAI Tools

Web Servers

Aspect Oriented Programming

Free Proxy Servers

Softwares

Adware & Spyware Remover

Open Source Softwares

Methods in Java
Expert:Danny
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 questions, which each are lalabeledith 4 answers, i was hoping it would end up looking up something similar to this.

Question 1:

Question will be here?

1) This will be possible answer 1
2) This will be possible answer 2
3) This will be possible answer 3
4) This will be possible answer 4

Your answer:
Correct answer: The correct answer will be displayed here
Your score: 0/10

I however, have no idea on how to create or run a method, we have begun to learn how to do this in class, but i'm not doing so well on it atm, so i was wondering if someone would be kind enuf to give me a guideline on how i would go about coding this, or if someone could show me or do it for me or whatever, you know what i mean, could someone help me please?

Thanks!
Answers
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

More Questions
Post Answers
 
Ask Question Facing Programming Problem?
Useful Links
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.