Saturday, 3 March 2012

Testing in console


import java.util.*;
public class Driver {

 
    public static void main(String[] args) {
        // TODO code application logic here
  System.out.print("Welcome to the test");
  Questions n=new Questions();
  for(int i=0; i<=3; i++){
   
      n.Ask(i);
   
  }
 n.result();
    }
}



import java.util.*;

public class Questions {

   public String[] q = {
       "WHich one is a multiple of 2",
       "WHos is the founder of pakistan",
       "Who is the founder of apple",
       "which one is a prime number"
   }, choice = {
       "1) 0.5   2) 5     3) 4    ",
       "1) MR zx        2) Qauid e azam     3) aer  ",
       "1) You   2) me     3) steve jobs    ",
       "1) 5   2) 4     3) 2    "
   };
   private int[] ans = {1, 2, 3, 5};
   private int correct = 0, wrong = 0, score;

   public Questions() {
   }
   Scanner in = new Scanner(System.in);
   public int[] stans = new int[ans.length];

     public void setq(String q,int index){this.q[index]=q;}
   public String getq(int index) {
       return q[index];
   }
      public void setchoice(String c,int index){this.choice[index]=c;}

   public String getchoice(int index) {
       return choice[index];
   }

   public void Ask(int index) {
       System.out.println(q[index]);
       System.out.println(choice[index]);
       stans[index] = in.nextInt();
       if(stans[index]<=0 || stans[index] >= 4){
        System.out.println("Wrong input your anser must be in between 1 and 3");
        stans[index] = in.nextInt();    
       }
       correct(stans[index], index);

   }

   public void correct(int stands, int index) {
       if (stans[index] == ans[index]) {
           correct++;
                                                                             score += 3;
       } else {
           wrong++;
           score -= 1;
       }
   }

   public void result() {
       System.out.println("Your correct answers are =",correct);

       System.out.println("Your wrong answers are =",wrong);
       System.out.println("Therefore your result is =",score);

   }
}

No comments:

Post a Comment