Results 1 to 2 of 2

Thread: if statement

  1. #1
    Exceedinglife is offline Member
    Join Date
    Apr 2012
    Posts
    17
    Rep Power
    0

    Default if statement

    hello,

    im trying to write an if statement so my arrays check each other and see if they are the same or not then im gunna add a counter for the correctlist and incorrect questions

    Java Code:
       private void gradeExam()
       {
         /* Missing code starts here */
    	  char[] correct = { 'B', 'D', 'A', 'A',
              'C', 'A', 'B', 'A',
              'C', 'D', 'B', 'C',
              'D', 'A', 'D', 'C',
              'C', 'B', 'D', 'A' };
    	  char[] student = new char[20];
    	  for(int i=0; i<correct.length; i++)
    	  {
    		  if(student[i] = correct[i]);
    		  System.out.print("Yoh have passed the test");
    	  }
         /* Missing code ends here */
         makeMissedArray();
       }
    [code]

  2. #2
    Exceedinglife is offline Member
    Join Date
    Apr 2012
    Posts
    17
    Rep Power
    0

    Default Re: if statement

    here is where i am currently at looking for tips

    Java Code:
    /**
     * DriverExam class
     */
    
    public class DriverExam
    {
       // Array containing the correct answers
       private char[] correct = { 'B', 'D', 'A', 'A',
                                  'C', 'A', 'B', 'A',
                                  'C', 'D', 'B', 'C',
                                  'D', 'A', 'D', 'C',
                                  'C', 'B', 'D', 'A' };
    
       private char[] student;       // The student's answers
       private int[] missed;         // The missed question numbers
       private int numCorrect = 0;   // The number correct
       private int numIncorrect = 0; // The number incorrect
       
       /**
        * Constructor
        * Accepts an array of the student's
        * answers as the argument. The contents
        * of the array are copied to the student
        * field.
        */
       
       public DriverExam(char[] s)
       {
          student = s;
          gradeExam();
       }
       
       /**
        * gradeExam method
        * This method determines the number of
        * correct and incorrect answers. It calls
        * the makeMissedArray method.
        */
       
       private void gradeExam()
       {
         /* Missing code starts here */
    	  char[] correct = { 'B', 'D', 'A', 'A',
              'C', 'A', 'B', 'A',
              'C', 'D', 'B', 'C',
              'D', 'A', 'D', 'C',
              'C', 'B', 'D', 'A' };
    	  char[] student = new char[20];
    	  for(int i=0; i<correct.length; i++)
    	  {
    		  if(student[i] == correct[i])
    		  	numCorrect++;
    		   	  
    	  }
         /* Missing code ends here */
         makeMissedArray();
       }  
       
       /**
        * makeMissedArray method
        * This method makes the missed array and
        * stores the numbers of all the questions
        * that the student missed in it.
        */
       
       private void makeMissedArray()
       {
         /* Missing code starts here */
    	   if(student[i] != correct[i])
    		   numIncorrect++;
         /* Missing code ends here */
       }
       
       /**
        * passed method
        */
       
       public boolean passed()
       {
          boolean status;
          
          if (numCorrect >= 15)
             status = true;
          else
             status = false;
             
          return status;
       }
       
       /**
        * totalCorrect method
        */
    
       public int totalCorrect()
       {
          return numCorrect;
       }
    
       /**
        * totalIncorrect method
        */
    
       public int totalIncorrect()
       {
          return numIncorrect;
       }
    
       /**
        * questionsMissed method
        * Returns an array containing the numbers
        * of the missed questions. If no questions
        * were missed, returns null.
        */
    
       public int[] questionsMissed()
       {
           return missed;
       }
    }

Similar Threads

  1. Replies: 2
    Last Post: 03-26-2012, 05:27 PM
  2. Mod and If Statement
    By Valerie1067 in forum New To Java
    Replies: 8
    Last Post: 03-25-2012, 09:00 AM
  3. if statement help please!!
    By soc86 in forum New To Java
    Replies: 5
    Last Post: 12-02-2008, 03:56 PM
  4. If statement, please help??
    By soc86 in forum New To Java
    Replies: 5
    Last Post: 11-23-2008, 03:58 PM
  5. Statement or Prepared Statement ?
    By paty in forum JDBC
    Replies: 3
    Last Post: 08-01-2007, 05:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •