1 2 3 4 5 6 Previous Next 80 Replies Latest reply on Mar 8, 2004 8:22 AM by 807551 Go to original post
      • 75. Re: .class expected error with arrays, help needed
        807551
        dude , how about if you answer one more qustion ? Its not even about my code. I understand what is going on and what i need to do but i cant figure out what this means. I tried search for it but didnt find anything understandable. Ok what i am doign is running my loop. It takes the first chatAt answerkey then gets the first char in the 2 dem array of paper[][] , Both operate fully to what i want to do because i tested with printlns (wonder where i learned that from) Ok my thing is when i pull both char , i want to first check to see if the responce is even a letter since students can answer Blanks on the test. Blanks equal to grade = grade + 0 there are not point given or taken away from entering blank. Now when i go to compare them i keep getting "char cannot be dereferenced" Error i dont understand that. I tried using the .isLetter() no luck. Then i thought maybe i have to make them strings, tried converting to a toString() no luck. I understand that somewhere/somehow i am NOT allowed to manipulate the char as it is. If that being the case then how and i make it so i can compare to other chars or strings ?

        p.S
        Is there (on this web site) a way to lookup/search compile errors ?
        • 76. Re: .class expected error with arrays, help needed
          796440
          Okay, this kind of question I can try to answer. It's fairly specific, and it's not one that I feel like I've already answered and am going around in circles on with you. ;-) (Don't take that personally--we all spin our wheels sometimes.)
          with printlns (wonder where i learned that from) Ok my
          thing is when i pull both char , i want to first check
          to see if the responce is even a letter since students
          can answer Blanks on the test. Blanks equal to grade =
          grade + 0 there are not point given or taken away
          from entering blank. Now when i go to compare them i
          keep getting "char cannot be dereferenced" Error i
          dont understand that. I tried using the .isLetter() no
          luck. Then i thought maybe i have to make them
          strings, tried converting to a toString() no luck. I
          understand that somewhere/somehow i am NOT allowed to
          manipulate the char as it is. If that being the case
          then how and i make it so i can compare to other chars
          or strings ?
          char is a primitive type, not an class, so you can't call methods on it. You can, however, compare it with == or use Character's static isLetter--you just have to use it correctly. You'll need to understand the difference betwee static (class) methods and non-static (instance) methods. Even though you can't call methods on primitives (e.g. aChar.something()) you can pass them as arguments to other methods. There are some methods on the Character class that operate on an instance of that class, and there are others--static methods--that don't require an instance of Character.
          char answer = answers[ix];
          if (answer == 'T' || answer == 't') { // here's one way to ignore case
              ...
          }
          else if (Character.toUpperCase(answer) == 'F') { // here's another
              ...
          }
           
          
          // OR
          
          if (Character.isLetter(answer)) {
              if (answer == correctAnswers[ix]) {
                  ...
              }
              else {
                  ...
              }
          }
          else { // it's not a letter
              ...
          }
          There are a few different cases that could occur, and different ways to test for them.

          * They give the correct T/F answer.

          * They give the wrong T/F answer.

          * They give an anser that is neither T nor F (space, number, punctuation, other letter...)
          p.S
          Is there (on this web site) a way to lookup/search
          compile errors ?
          Not that I know of, but presumably you know how to use google? (I tried it using three key words and got over 20,000 matches. Changing one of the words by one letter gave me about 10 times as many.)
          • 77. Re: .class expected error with arrays, help needed
            807551
            . Ummm can you stear me right here. Im almost done !!! (need to get done tonight) Ok I have evrything i need, i can return the grade in decimal format which i set to 0.00 . The reason i did this is cause not only do i have to return the grade number but also the grade letter. Which i would see a switch working just perfectly . Ok i understand the format and understand it accepts integral only. how can i say between ** and ** without making boolean ??
            switch (exp)
            {
            case value1: statement
            break;

            and so on
            }
            but at the point of value how can i put in almost like a if statement if possible. The reason asking is this is my fomrat for getting grade
            A = 90-100%
            B = 80-89.99%
            C = 70-79.99%
            D = 60-69.99%
            F = 0-59.99 %

            i know that what i need to do is say

            switch(gradepercent)
            {
            case if( between 80 to 89.99) : B

            and so on.

            this is something i had
                        switch(grade)
                        {
                             case gradepercent >= 90.00:System.out.println("A");
                                                 break;
                             case gradepercent <= 59.99:System.out.println("F");
                                                 break;
                             case gradepercent >= 60 && gradepercent <= 69.99:System.out.println("D");
                                                 break;
                             case gradepercent >= 70.00 && gradepercent <= 79.99:System.out.println("C");
                                                 break;
                             case gradepercent >= 80.00 && gradepercent <= 89.99:System.out.println("B");
                                                 break;
                             default: System.out.println("The grade was invaild.");
                        }
            A:\History.java:58: incompatible types
            found : boolean
            required: int
                           case gradepercent >= 90.00:System.out.println("A");
            ^
            A:\History.java:60: incompatible types
            found : boolean
            required: int
                           case gradepercent <= 59.99:System.out.println("F");
            ^
            A:\History.java:62: incompatible types
            found : boolean
            required: int
                           case gradepercent >= 60 && gradepercent <= 69.99:System.out.println("D");
            ^
            A:\History.java:64: incompatible types
            found : boolean
            required: int
                           case gradepercent >= 70.00 && gradepercent <= 79.99:System.out.println("C");
            ^
            A:\History.java:66: incompatible types
            found : boolean
            required: int
                           case gradepercent >= 80.00 && gradepercent <= 89.99:System.out.println("B");
            • 78. Re: .class expected error with arrays, help needed
              807551
              please disregart the "but at the point of value how can i put in almost like a if statement if possible. The reason asking is this is my fomrat for getting grade " statement. i wrote the replay , then i tried it and i know it doesnt work.
              • 79. Re: .class expected error with arrays, help needed
                796440
                Well, you could do it with a switch statement I suppose, but why would you want to? You've got a nice, regular 90, 80, 70, 60 pattern there, so you just divide by ten and truncate, if you really have to do it with a switch, but I'd do it like this:
                if (score >= 90) {
                    ...
                }
                else if (score >= 80) {
                    ...
                } 
                • 80. Re: .class expected error with arrays, help needed
                  807551
                  Ok man this is all my code. The only thing that it isnt doing is when it gets a space its like it goes into a infinite loop and nevre ends, other than that it works. i have class in 3 hrs and need sleep hah thanks man for all info. I will try more maybe in mroning. Thank you again jverd
                  import java.io.*;
                  import java.util.*;
                  import java.text.*;
                  
                  
                  public class History
                  {
                       public static String getAnswerKey(BufferedReader infile) throws IOException
                       {
                  
                            String answerkey = infile.readLine();
                  
                            return answerkey;
                  
                       }
                  
                       public static void getPaperGrade(BufferedReader infile,PrintWriter outfile, char[][] paper, String answerkey) throws IOException, NoSuchElementException
                       {
                  
                            String str, tempname = "", tempresponces = "", lettergrade = "";
                            StringTokenizer tokenizer;
                            char tempanswerkey, tempstudentresponce;
                            double grade = 0;
                            double gradepercent;
                            DecimalFormat toDecimal = new DecimalFormat("00.0");
                  
                  
                            str = infile.readLine();
                  
                            while(str != null)
                            {
                                 tokenizer = new StringTokenizer(str);
                                 String studentID = tokenizer.nextToken();
                  
                                 tempname = studentID;
                  
                                 for(int i = 0; i < studentID.length(); i++)
                                      paper[0] = studentID.charAt((i));

                                 String responces = tokenizer.nextToken();
                                 tempresponces = responces;

                                 for(int k = 0; k < responces.length(); k++)
                                      paper[k][1] = responces.charAt((k));


                                 for(int i = 0; i < answerkey.length(); i++)
                                 {
                                      tempanswerkey = answerkey.charAt((i));
                                      tempstudentresponce = paper[i][1];


                                 if(Character.isLetter(tempstudentresponce))
                                      if(tempanswerkey == tempstudentresponce)
                                           grade = grade + 2;
                                      else
                                           grade = grade - 1;
                                 else
                                      grade = grade + 0;
                                 }

                            }

                            gradepercent = (grade * 100) / 40; //takes grade , gets percentage of grade


                            if(gradepercent >= 90)
                                 lettergrade = "A";
                            else if(gradepercent >= 80)
                                 lettergrade = "B";
                            else if(gradepercent >= 70)
                                 lettergrade = "C";
                            else if(gradepercent >= 60)
                                 lettergrade = "D";
                            else if(gradepercent >= 0)
                                 lettergrade = "F";
                            else if(gradepercent < 0)
                                 lettergrade = "F";

                            grade = 0;

                            outfile.println("StudentID: " + tempname + " Responces: " + tempresponces + " Score: " + gradepercent + " Grade: " + lettergrade);

                            str = infile.readLine();

                  }
                  }
                  import java.io.*;
                  
                  
                  public class HistoryTest
                  {
                  
                       public static void main(String[] args) throws IOException
                       {
                            BufferedReader infile = new BufferedReader(new FileReader("a:\\Input.txt"));
                            PrintWriter outfile = new PrintWriter(new FileWriter("a:\\output.txt"));
                            History hs = new History();
                            char paper[][] = new char[20][2];
                  
                  
                            String answerkey = hs.getAnswerKey(infile);
                            hs.getPaperGrade(infile,outfile, paper, answerkey);
                  
                            infile.close();
                            outfile.close();
                       }
                  
                  }
                  1 2 3 4 5 6 Previous Next