Results 1 to 2 of 2
  1. #1
    Sly Cooper is offline Member
    Join Date
    Jan 2011
    Posts
    10
    Rep Power
    0

    Default Java Program: Grading using Arrays [Help]

    Ok so here's the code my friend and I have made so far

    Java Code:
    /**
     * @(#)miatasGroup.java
     *
     * miatasGroup application
     *
     * @author
     * @version 1.00 2011/1/29
     */
    
    import java.io.*;
    import java.util.StringTokenizer;
    
    public class miatasGroup {
    
     private static FileInputStream inFile;
     private static InputStreamReader inReader;
     private static  BufferedReader reader;
    
    public static void main(String[] args) throws IOException {
    
      initFile();
      getData();
      inFile.close();
    }
    
    public static void initFile() throws IOException {
    
      String locationFile = new File("TestSheet.txt").getAbsolutePath();
      inFile = new FileInputStream (locationFile);
      inReader = new InputStreamReader(inFile);
      reader = new BufferedReader(inReader);
    }
    
    public static void getData() throws IOException {
    
    
      String line = reader.readLine();
      StringTokenizer strTkn;
        strTkn = new StringTokenizer(line);
        String answer = strTkn.nextToken();
        System.out.println("The answers for the test are as follows: " + answer + " T standing for True, and F standing for False.");
        System.out.println("-----------------------------------------------------------------------------------------------------");
    
    
      String answerKey = line;
      StringTokenizer tokens;
      while((line = reader.readLine()) != null) {
        int total = 1;
        int counter0 = 0;
        int counter1 = 0;
        int counter2 = 0;
        int counter3 = 0;
        int counter4 = 0;
        int counter5 = 0;
        int counter6 = 0;
        int counter7 = 0;
        int counter8 = 0;
        int counter9 = 0;
    
        int[] studentID = {1, 2};
        String[] studentAnswers = {"a", "b"};
        tokens = new StringTokenizer(line);
        studentID[total] = Integer.parseInt(tokens.nextToken());
        studentAnswers[total] = tokens.nextToken();
        total++;
    
       if (studentAnswers[1].charAt(0) == 'T'){
          counter0 = counter0 + 1;
       }else{
            }
    
       if (studentAnswers[1].charAt(1) == 'T'){
          counter1++;
       }else{
            }
    
    
       if (studentAnswers[1].charAt(2) == 'T'){
          counter2++;
       }else{
            }
    
    
       if (studentAnswers[1].charAt(3) == 'T'){
          counter3++;
       }else{
            }
    
    
       if (studentAnswers[1].charAt(4) == 'T'){
          counter4++;
       }else{
            }
    
    
       if (studentAnswers[1].charAt(5) == 'T'){
          counter5++;
       }else{
            }
    
    
       if (studentAnswers[1].charAt(6) == 'T'){
          counter6++;
       }else{
            }
    
    
       if (studentAnswers[1].charAt(7) == 'T'){
          counter7++;
       }else{
            }
    
       if (studentAnswers[1].charAt(8) == 'T'){
          counter8++;
       }else{
            }
    
       if (studentAnswers[1].charAt(9) == 'T'){
          counter9++;
       }else{
            }
    
     int numberscorrect = (counter0 + counter1 + counter2 + counter3 + counter4 + counter5 + counter6 + counter7 + counter8 + counter9);
    
      System.out.println("Student number: " + studentID[1] + " Answered " + numberscorrect + " Correctly out of 10, and recieved a grade of: " + "__ " + "With the answers: " + studentAnswers[1]);
    
      }
      }
      }
    
    
    
    
    
    
    Output:
    
    The answers for the test are as follows: TFFTFTTFTT T standing for True, and F standing for False.
    -----------------------------------------------------------------------------------------------------
    Student number: 918 Answered 7 Correctly out of 10, and recieved a grade of: __ With the answers: TFTTFTFTTT
    Student number: 5263 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: FFFFTFTTTF
    Student number: 1067 Answered 1 Correctly out of 10, and recieved a grade of: __ With the answers: FFFFFFFTFF
    Student number: 2838 Answered 6 Correctly out of 10, and recieved a grade of: __ With the answers: TFTFTTFTFT
    Student number: 6372 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: FFTFFFTTTF
    Student number: 8911 Answered 6 Correctly out of 10, and recieved a grade of: __ With the answers: FTTTTTFTFF
    Student number: 1625 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: FTFFFFFTTT
    Student number: 6764 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: TTTFFFFFFT
    Student number: 4933 Answered 6 Correctly out of 10, and recieved a grade of: __ With the answers: FFFTTTTTFT
    Student number: 4375 Answered 6 Correctly out of 10, and recieved a grade of: __ With the answers: TTTTFFFTTF
    Student number: 3113 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: FTTFTTFTFF
    Student number: 9598 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: FFFTFTFTFT
    Student number: 5224 Answered 1 Correctly out of 10, and recieved a grade of: __ With the answers: FFFFFFFFTF
    Student number: 5962 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: FFTFFTTTFT
    Student number: 7626 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: TFFFFTFTFT
    Student number: 117 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: TFFFFFTTFT
    Student number: 4116 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: TFTTFFFTFF
    Student number: 8596 Answered 8 Correctly out of 10, and recieved a grade of: __ With the answers: TTFTTTTFTT
    Student number: 9525 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: FTFTTFFTFF
    Student number: 7422 Answered 7 Correctly out of 10, and recieved a grade of: __ With the answers: FTFTFTTTTT
    Student number: 7297 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: FFFTTTFFTF
    Student number: 142 Answered 7 Correctly out of 10, and recieved a grade of: __ With the answers: TTTFTTFTTF
    Student number: 6870 Answered 6 Correctly out of 10, and recieved a grade of: __ With the answers: FFTTFFTTTT
    Student number: 1201 Answered 3 Correctly out of 10, and recieved a grade of: __ With the answers: FTFTFTFFFF
    Student number: 9264 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: FTFTTFFFTF
    Student number: 641 Answered 2 Correctly out of 10, and recieved a grade of: __ With the answers: FTFFFFFTFF
    Student number: 1763 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: FFTTFTTFFT
    Student number: 3742 Answered 7 Correctly out of 10, and recieved a grade of: __ With the answers: FTFTFTTTTT
    Student number: 2349 Answered 3 Correctly out of 10, and recieved a grade of: __ With the answers: FTTFFFFFTF
    Student number: 3731 Answered 7 Correctly out of 10, and recieved a grade of: __ With the answers: TFTTFTFTTT
    Student number: 1510 Answered 7 Correctly out of 10, and recieved a grade of: __ With the answers: FFTTFTTTTT
    Student number: 7316 Answered 3 Correctly out of 10, and recieved a grade of: __ With the answers: FFFFTFTTFF
    Student number: 505 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: FTFTTFFFTT
    Student number: 6274 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: TTFTFFFFTF
    Student number: 8413 Answered 6 Correctly out of 10, and recieved a grade of: __ With the answers: FTTFFFTTTT
    Student number: 2933 Answered 2 Correctly out of 10, and recieved a grade of: __ With the answers: TFFFFFFFFT
    Student number: 132 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: TTFFTFFFTF
    Student number: 942 Answered 6 Correctly out of 10, and recieved a grade of: __ With the answers: TTTTTFFFFT
    Student number: 4398 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: FTTTTTFFFF
    Student number: 9670 Answered 8 Correctly out of 10, and recieved a grade of: __ With the answers: FTTTTTTTTF
    Student number: 7080 Answered 8 Correctly out of 10, and recieved a grade of: __ With the answers: TTTTFTTFTT
    Student number: 896 Answered 6 Correctly out of 10, and recieved a grade of: __ With the answers: TTFFTTTTFF
    Student number: 7280 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: TFFFTTFFFT
    Student number: 9570 Answered 7 Correctly out of 10, and recieved a grade of: __ With the answers: FTTTTTFTFT
    Student number: 6753 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: TTFFFFFFTT
    Student number: 5788 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: FTTTFTFFTF
    Student number: 8916 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: TFTFFTFTFT
    Student number: 8255 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: TFFTFTTFFT
    Student number: 1285 Answered 3 Correctly out of 10, and recieved a grade of: __ With the answers: FFFFFTTTFF
    Student number: 7745 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: TTTFTFFFFT
    Student number: 2529 Answered 8 Correctly out of 10, and recieved a grade of: __ With the answers: TFTTTTTFTT
    Student number: 5393 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: FTFFTFFTTT
    Student number: 107 Answered 8 Correctly out of 10, and recieved a grade of: __ With the answers: FTTTFTTTTT
    Student number: 4922 Answered 6 Correctly out of 10, and recieved a grade of: __ With the answers: FFFTTTTFTT
    Student number: 674 Answered 7 Correctly out of 10, and recieved a grade of: __ With the answers: FFTFTTTTTT
    Student number: 7223 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: FTFFTTTFFF
    Student number: 110 Answered 7 Correctly out of 10, and recieved a grade of: __ With the answers: FTTTTTFTFT
    Student number: 5111 Answered 6 Correctly out of 10, and recieved a grade of: __ With the answers: FFTFTFTTTT
    Student number: 8030 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: FTFTFFFFTT
    Student number: 3876 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: FFTTFTFFTT
    Student number: 932 Answered 3 Correctly out of 10, and recieved a grade of: __ With the answers: FTFFFTFTFF
    Student number: 770 Answered 8 Correctly out of 10, and recieved a grade of: __ With the answers: TTTTFFTTTT
    Student number: 8111 Answered 7 Correctly out of 10, and recieved a grade of: __ With the answers: TTFTTTTFTF
    Student number: 6899 Answered 3 Correctly out of 10, and recieved a grade of: __ With the answers: FFTFFTTFFF
    Student number: 9844 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: FFFTFTTTTF
    Student number: 6719 Answered 2 Correctly out of 10, and recieved a grade of: __ With the answers: TFFFFFFFFT
    Student number: 2335 Answered 6 Correctly out of 10, and recieved a grade of: __ With the answers: TFTFTFTFTT
    Student number: 8046 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: FFTFFFTTFT
    Student number: 408 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: FFTFTTTTFF
    Student number: 6362 Answered 6 Correctly out of 10, and recieved a grade of: __ With the answers: TFTTFTTFFT
    Student number: 9538 Answered 6 Correctly out of 10, and recieved a grade of: __ With the answers: FTTFFTTTFT
    Student number: 9732 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: TTFFTTFTFF
    Student number: 9478 Answered 6 Correctly out of 10, and recieved a grade of: __ With the answers: FTTFTFFTTT
    Student number: 8874 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: TFTTFFTTFF
    Student number: 1294 Answered 7 Correctly out of 10, and recieved a grade of: __ With the answers: TTTTTFFFTT
    Student number: 9798 Answered 6 Correctly out of 10, and recieved a grade of: __ With the answers: TFFTTFTFTT
    Student number: 8779 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: TFFFFTTFFT
    Student number: 8 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: FTFTTFFFFT
    Student number: 8319 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: FFTFFTTTFF
    Student number: 522 Answered 7 Correctly out of 10, and recieved a grade of: __ With the answers: FTTTTTFTTF
    Student number: 9684 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: TFFFTTFFTT
    Student number: 4467 Answered 6 Correctly out of 10, and recieved a grade of: __ With the answers: FFTTFTFTTT
    Student number: 7266 Answered 3 Correctly out of 10, and recieved a grade of: __ With the answers: FFFTFFTTFF
    Student number: 1015 Answered 3 Correctly out of 10, and recieved a grade of: __ With the answers: FFTTFTFFFF
    Student number: 2932 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: FTFTFFTFFT
    Student number: 474 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: TFTTTFFFFF
    Student number: 5022 Answered 9 Correctly out of 10, and recieved a grade of: __ With the answers: TTTTTTTTFT
    Student number: 2071 Answered 6 Correctly out of 10, and recieved a grade of: __ With the answers: TFTTFTTFFT
    Student number: 4084 Answered 7 Correctly out of 10, and recieved a grade of: __ With the answers: FFTTTFTTTT
    Student number: 6416 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: FFTFTTFFTF
    Student number: 4926 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: TFTFTTFTFF
    Student number: 1131 Answered 6 Correctly out of 10, and recieved a grade of: __ With the answers: TTFFFTTTTF
    Student number: 8182 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: FTFFFTFFTT
    Student number: 86 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: TFFFFTTTFT
    Student number: 9926 Answered 6 Correctly out of 10, and recieved a grade of: __ With the answers: TTTTTFFTFF
    Student number: 2093 Answered 7 Correctly out of 10, and recieved a grade of: __ With the answers: TTTTFTFTTF
    Student number: 733 Answered 6 Correctly out of 10, and recieved a grade of: __ With the answers: FFTTTTFFTT
    Student number: 8281 Answered 10 Correctly out of 10, and recieved a grade of: __ With the answers: TTTTTTTTTT
    Student number: 8824 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: FTTFFFTFTT
    Student number: 2910 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: FTFFFTFTTF
    Student number: 8457 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: FFFFFTFTTT
    Student number: 465 Answered 2 Correctly out of 10, and recieved a grade of: __ With the answers: TFFFFTFFFF
    Student number: 1575 Answered 8 Correctly out of 10, and recieved a grade of: __ With the answers: TTTFTFTTTT
    Student number: 3186 Answered 6 Correctly out of 10, and recieved a grade of: __ With the answers: FFFTTTTTTF
    Student number: 5833 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: FTFTFFTFTT
    Student number: 3985 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: FTTTFFFTTF
    Student number: 5844 Answered 7 Correctly out of 10, and recieved a grade of: __ With the answers: TTFTTFTTTF
    Student number: 5669 Answered 3 Correctly out of 10, and recieved a grade of: __ With the answers: FFFFFTTFFT
    Student number: 9905 Answered 9 Correctly out of 10, and recieved a grade of: __ With the answers: TTTTFTTTTT
    Student number: 5591 Answered 6 Correctly out of 10, and recieved a grade of: __ With the answers: FTTTFFTTFT
    Student number: 6135 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: FTFFTTTFTF
    Student number: 9764 Answered 6 Correctly out of 10, and recieved a grade of: __ With the answers: FTFFTFTTTT
    Student number: 2848 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: TFTFTTFTFF
    Student number: 1525 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: TTFFFFTTFT
    Student number: 8291 Answered 7 Correctly out of 10, and recieved a grade of: __ With the answers: TTTFTTTTFF
    Student number: 5011 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: FTFTTTFTFF
    Student number: 1632 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: FFTTFFFTTT
    Student number: 3123 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: FTTTTFTFFF
    Student number: 7889 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: TFTFFTFTFT
    Student number: 3024 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: FTFFTFFTFT
    Student number: 9165 Answered 7 Correctly out of 10, and recieved a grade of: __ With the answers: TTFTFTTTFT
    Student number: 754 Answered 3 Correctly out of 10, and recieved a grade of: __ With the answers: FFFFFTFFTT
    Student number: 6670 Answered 3 Correctly out of 10, and recieved a grade of: __ With the answers: FFTTFFTFFF
    Student number: 2752 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: TTFFFTFFTF
    Student number: 2021 Answered 5 Correctly out of 10, and recieved a grade of: __ With the answers: FFTTFTTTFF
    Student number: 5428 Answered 4 Correctly out of 10, and recieved a grade of: __ With the answers: FFTTTTFFFF
    Student number: 4292 Answered 7 Correctly out of 10, and recieved a grade of: __ With the answers: TFFTTTFTTT
    Basically what I need know is how to replace those underscores with the grades that each student got on the test out of 10. (ie if they get 7 out of 10 then they recieve a C on it, using A B C D, and F for failure)

    All help is appreciated. :)
    Last edited by Sly Cooper; 01-30-2011 at 07:37 AM.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    Basically what I need know is how to replace those underscores with the grades that each student got on the test out of 10.

    Write a method that calculates the grade:

    Java Code:
        /**
         * Returns the grade letter corresponding to a given number of correct answers.
         */
    private static char calcGrade(int numCorrect) {
        // Your code here
        // if(numCorrect == 7) return 'C';  ???
        // or switch(numCorrect) {  ???
    }

    Then use that in the string you print. Ie replace

    Java Code:
    + "__ " +

    with

    Java Code:
    + calcGrade(numberscorrect) +

Similar Threads

  1. Converting Program from ArrayLists to Arrays
    By Java-Guy in forum New To Java
    Replies: 3
    Last Post: 01-26-2011, 10:02 AM
  2. Replies: 1
    Last Post: 03-11-2010, 01:49 AM
  3. Java program problem.. Arrays.. Random Numbers
    By Chewart in forum New To Java
    Replies: 16
    Last Post: 11-16-2009, 11:21 PM
  4. Need help with program: arrays
    By dangerzone9k in forum New To Java
    Replies: 2
    Last Post: 04-02-2009, 06:59 AM
  5. Replies: 2
    Last Post: 11-18-2008, 11:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •