File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Array Project Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array Project Help" Watch "Array Project Help" New topic
Author

Array Project Help

Timothy Scott
Greenhorn

Joined: Apr 23, 2009
Posts: 7

HERE IS MY PROJECT BELOW:

The local drivers license office needs a program that grades the written portion of the drivers license exam. Your program will prompt the user for their 20 responses to the multiple choice questions. compare them to the correct answers, and print some statistics about their score. You will continue grading as long as the user indicates they have more input.

DATA STRUCTURES REQUIRED: 2 Character arrays. One will be initalized with correct answers and the other will be filled with student grades.

INPUT: 20 Characters that will be stored in a character array. Validate each character. Only accept A B C D

Write the following methods to perform the processing of the array. After the first student ask the user if they have more exams to grade. Repeat the grading process as long as the user wishes. You may use more methods if you wish but at least 2.

OUTPUT: A summary of the students results which includes the # of incorrect answers the question number of incorrect answers and a pass or fail message.

CORRECT ANSWERS:{'B', 'B', 'C', 'B', 'A', 'A', 'A', 'A',
'B', 'A', 'B', 'A', 'D', 'C', 'D', 'D',
'B', 'A', 'C', 'A' };

---------------------------------------------------------------------------------------------------
My if input validation doesn't seem to work here is the error I'm getting I'm also stumped on how to move forward.
That doesn't seem to work this is the error I'm getting File:
[line: 23]
Error: C:\Documents and Settings\Tim\Desktop\javaprograms\Projects\ArrayDriversLicense.java:23: incomparable types: char[] and char cannot find symbol
symbol : variable i

Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3829

incomparable types: char[] and char............


As the compiler complains you are comparing char[] (array of char) against char which is not comparable. You should compare the values in the array using index (i.e: userinput[index]) instead.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Timothy Scott
Greenhorn

Joined: Apr 23, 2009
Posts: 7
is it possible for you to put the whole thing into code format I tried doing what you said and it still didnt work
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3829

I didn't go through your code to get your logic, but as I see you have few problems in comparing two values as I pointed out above and trying to use variable "i" out of the scope ( "for" loop which it declared). Check the scopes of those variables.
Nishant Arora
Greenhorn

Joined: Apr 21, 2009
Posts: 16
at line no 19 you should use userinput[i] while comparing.
at line no 25 you will not have scope of i declare it outside for.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I see an infinite loop. Can you see it ?


[My Blog]
All roads lead to JavaRanch
Nishant Arora
Greenhorn

Joined: Apr 21, 2009
Posts: 16
//I modified your code may be you modify it further as per your requirement
//Is this the output you want to have???

import java.util.Scanner;
public class ArrayDriverLicense
{
public static void main (String [] args)
{
Scanner keyboard = new Scanner(System.in);
String input=null;
int sum = 0,i=0,correct=0;
char [] answers = {'B', 'B', 'C', 'B', 'A', 'A', 'A', 'A','B', 'A', 'B', 'A', 'D', 'C', 'D', 'D','B', 'A', 'C', 'A' };
char [] userinput ;

System.out.println("Please enter all your 20 answers using only A TO D without space then press Enter");
Deleted: see this FAQ

System.out.println("You missed " +sum + " questions.");
System.out.println("Correct Answer "+correct);
if(correct==20)
System.out.println("You scored a 100%");
}
catch(ArrayIndexOutOfBoundsException unmatched)
{
System.out.println("no of answer does not match the no of question No Calculation");
}

}
}
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
Please don't give answers like that. This is an assessed exercise, and you are doing nobody any favours by giving answers. Read the FAQ I linked to.

By the way: your answer contains an error in the form of catch (ArrayIndexOutOfBoundException) which should lose a few marks
Timothy Scott
Greenhorn

Joined: Apr 23, 2009
Posts: 7
I've changed my logic around and still seem to be having a problem with my nested for loop it seems to repeat Please enter your answers using only A-D numerous times because row keeps getting reset to 0 everytime the statement is false so I'm first wondering how to correct that. I'm then having trouble coming up with a way for the loop to log the correct answer if it is correct and to log the incorrect answers as well. If anyone could help I'd appreciate it.

Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
This...



...will always return true which means you can never get past entering a grade.

Walkthrough the logic...
- User enters 'A'

if(user did not enter a (false) OR user did not enter b (true) OR user did not enter c (true) OR user did not enter d (true)) True or anything else always returns true so you will always enter this conditional statement. I think you can solve all your codes issues by just walking through your code's logic one line at a time on a seperate piece of paper.

HTH GL.


SCJA
~Currently preparing for SCJP6
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
Look at the line beginning "if (userInput != . . . ."
Read it very carefully, then write down what it means. I shall give you a start.

"If the userInput variable entered i-th is not equal to A . . .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array Project Help