Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Need so help with my java homework
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
SHOPPINGGIRL11




PostPosted: Sun Apr 25, 2010 10:33 pm   Post subject: Need so help with my java homework

Hey, for my homework I have to make a program that will read information from an answers key file. Store the information in an answer key array, the answers can only be a,b,c,d. The program will then read the information from a student answer file, in this file there will be the number of students on one line then the name of the student followed by the students 10 answers. Everything is on its own line in the file. The program will store the marks in an array. For each student compaire the answers, keep a count of correct answers and output the student name, state if each answer is correct or incorrect and the total correct score.
Ok so right know I have read the answer key file and stored the variables in an array.
code:

    FileReader fr = new FileReader ("answerKey.txt");
    BufferedReader bfr = new BufferedReader (fr);
   
    int test_Num  = 0;
    final int MAX = 10;
    String input = " ";
    char a = 'a';
    char b = 'b';
    char c = 'c';
    char d = 'd';
    char i = 'i';
    char answerKey[] = new char[MAX];
    char studnent_Answers[] = new char[test_Num];
    int total = 10;
    int num_Students = 0;
    String student_Name = " ";
     
    for (int count = 0; count < MAX; count++)
    {
      input = bfr.readLine ();
      char ch = input.charAt(answerKey[count]);
     
      if (ch == a)
      {
        answerKey [count] = ch;
      }
      else if (ch == b)
      {
        answerKey [count] = ch;
      }
      else if (ch == c)
      {
        answerKey [count] = ch;
      }
      else if (ch == d)
      {
        answerKey [count] = ch;
      }
      else
      {
        ch = i;
        answerKey [count] = ch;
        total--;
      }
    }
    fr.close();
    FileReader fr = new FileReader ("studentResults.txt");
    num_Students = bfr.readLine ();
    test_Num = num_Students * MAX;
   
    student_Name = bfr.readLine ();
   
    for (int count = 0; count < MAX; count++)
    {
      input = bfr.readLine ();
      char ch = input.charAt(student_Answers[count]);
    }
  }
}


I am having trouble reading from the second file, I have never read from 2 diffrent files in the same program before so I keep getting an error. Sad
Also I was wondering how to read the diffrent types of information in the sudent answers file should I use 3 variables to do that one array of chars for the answers, a string variable for the name and a int variable for the number of studnets in a file? As you can see in my code tht is what I have attempted to do.. didnt work out so well Sad

Thank you for your help in advance!
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Sun Apr 25, 2010 11:59 pm   Post subject: RE:Need so help with my java homework

First things first... Java won't compile a class with duplicate local variables.
Barbarrosa




PostPosted: Mon Apr 26, 2010 4:40 am   Post subject: Re: Need so help with my java homework

wtd's right. You can assign a different object reference value to a variable, but that does not entail declaring its type again.

Java:

    Object o = new Object();//assigning (and constructing) with declaring type
    o = new Object();//assigning (and constructing) without declaring type
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: