Results 1 to 2 of 2
Thread: if statement
- 04-25-2012, 12:59 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 17
- Rep Power
- 0
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
[code]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(); }
- 04-25-2012, 01:25 AM #2
Member
- Join Date
- Apr 2012
- Posts
- 17
- Rep Power
- 0
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
-
the switch statement and unreachable statement error
By name in forum New To JavaReplies: 2Last Post: 03-26-2012, 04:27 PM -
Mod and If Statement
By Valerie1067 in forum New To JavaReplies: 8Last Post: 03-25-2012, 08:00 AM -
if statement help please!!
By soc86 in forum New To JavaReplies: 5Last Post: 12-02-2008, 02:56 PM -
If statement, please help??
By soc86 in forum New To JavaReplies: 5Last Post: 11-23-2008, 02:58 PM -
Statement or Prepared Statement ?
By paty in forum JDBCReplies: 3Last Post: 08-01-2007, 04:45 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks