• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Comparing String array to int list

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have created 2 methods.One to import a file and 2 to get scores for each student by using the data and comparing it against the answer key. Although the methods work fine independantly I have struggled to make them work together.Any suggestions/help? here are the methods. I have tried parsing from data String to int t compare with the answer key and vice versa and numerous other thing but to no avail. Please help if possible.
First part of code to test for scoring
final int T = 1;
final int F = 0;
int[] userAnswers = {80,F,T,F,F,T,F,F,T,F,T};
int[] answerKey = {F,T,F,F,T,F,F,T,F,T};
int userScore = 0;
System.out.println("ID="+userAnswers[0]);
for (int i=0; i<answerKey.length; i++) {
if (userAnswers[i+1] == answerKey) {
userScore++);
}
}
System.out.println(userScore++);
}
}
import java.io.*;
import javax.swing.JOptionPane;

2nd part of code to import data
final int T = 1;
final int F = 0;
String[] students =new String[];
int[] answerKey = {F,T,F,F,T,F,F,T,F,T}; //Array answer key for scores processing
int userScore = 0;
public void enterStudentInfo()
{
try {
// Create object ins - the input file. FileReader inStream = new FileReader("a:/student.txt");
BufferedReader ins = new BufferedReader(inStream);
int i = 0;
for (int lineCount = 0; lineCount < 10; lineCount++) {
students[i] = ins.readLine();
System.out.println(students); //Test if the data comes in
}
}
catch (IOException ex) {
System.out.println("i/o error: " + ex.getMessage());
ex.printStackTrace();
}
catch (NumberFormatException ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
}
}
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic