userpane
userpane

Reputation: 127

How to do a grading system with pre-given list of integers in java?

I would like to convert a list of marks given to grade.

public static void main (String[] arg){

   int[] m= Student.getMarks();

}

public static char grade (int[] m){
  int[] lowestg = {80,70};
  char[] g = new char[m.length];
  for (int x=0; x<m.length; x++){
    n=0;        
    for (int y=0; y<m.length; y++){
       if (m[x]>=lowestg[0]){
        g[y] = 'H';
       }
       else if (m[x]>=lowestg[1]){
        g[y] = 'D';
       }
       else 
        g[y] = 'F';
    }
  return g;
  }
 }

I would also like to put that into an array of characters.

When I tried to build it, it is shwoing

error: incompatible types

Upvotes: 1

Views: 246

Answers (2)

johnchen902
johnchen902

Reputation: 9609

Your code is unclear. I guess this is what you want.

public static char[] grade(int[] m) {
    char[] g = new char[m.length];
    for (int i = 0; i < m.length; i++) {
        if (m[i] >= 80)
            g[i] = 'H';
        else if (m[i] >= 70)
            g[i] = 'D';
        else
            g[i] = 'F';
    }
    return g;
}

It's public static char[] grade(int[] m) not public static char grade(int[] m) in my code.

Upvotes: 0

Eugene
Eugene

Reputation: 121078

 g[y] = 'HD'  --> HD is not a char...

You can change the char [] g, to String [] g

Upvotes: 3

Related Questions