• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Array Project Help

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Timothy Scott
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see an infinite loop. Can you see it ?
 
Nishant Arora
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
//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");
}

}
}
 
Marshal
Posts: 80749
486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Marshal
Posts: 80749
486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 . . .
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic