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

Username:   Password: 
 RegisterRegister   
 test score array to letter grade array
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
bryce_21




PostPosted: Wed Apr 16, 2014 5:52 pm   Post subject: test score array to letter grade array

A is >=90
B is 80-89
C is 70-79
D is 60-69
F <60
int [] grades = new int[100];
here the java code
char [] scores = double[grade];
for (int i=0; i.length; i++) {
if (grades[i] >=90)
grades='A';
else if(grades[i] >=80)
grades= 'B';
else if (grades[i] >=70)
grades= 'C';
else if (grades[i] >=60)
grades= 'D';
else (grades[i] <60)
grades= 'F';
} return grades;
}

how to return a character array of letter grades that corresponds to the int array of numerical grades
Sponsor
Sponsor
Sponsor
sponsor
Zren




PostPosted: Wed Apr 16, 2014 8:03 pm   Post subject: RE:test score array to letter grade array

return = Return a value from a function.

code:

public static RETURNED_DATA_TYPE toLetterGrades(int[] numericalGrades) {
    ...
    return RETURNED_VALUE;
}


array of ______

code:
DATATYPE[] variableName = new DATATYPE[SIZE];


The datatype for "letter grades" is represented as a "character". Thus: DATATYPE = char

With that knowledge:

code:
char[] letterGrades = new char[SIZE];


code:

public static char[] toLetterGrades(int[] numericalGrades) {
    char[] letterGrades ...
    ...
    return letterGrades;
}


The algorithm for toLetterGrades would be something along the lines of:
code:

for each index of numericalGrades:
    numericalGrade = numericalGrade[i]
    letterGrade = convertNumericalGradeToLetterGrade(numericalGrade)


You can substitute "for each index of an array" with:
code:
for (int i = 0; i < arrayName.length; i++) { ... }





* Insert futile attempt asking to keep all your questions to the same thread. *
bryce_21




PostPosted: Wed Apr 16, 2014 8:44 pm   Post subject: RE:test score array to letter grade array

convertNumericalGradeToLetterGrade(numericalGrade)

quick question what does this statement above java means
Zren




PostPosted: Wed Apr 16, 2014 10:00 pm   Post subject: RE:test score array to letter grade array

It's the syntax for calling a function.

functionName(parameter1, parameter2, ...)

Basically, I was hinting that you should make a second function that accepts a parameter representing the numerical grade, and returns a character which represents the letter grade of the given numerical grade.

Edit: I purposely used a super long name instead of toLetterGrade (note the singular) so you wouldn't get confused with the first function which accepts an array and returns an array. This second function should accept an integer and return a character.
bryce_21




PostPosted: Thu Apr 17, 2014 12:22 am   Post subject: RE:test score array to letter grade array

thanks for all your help....
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  [ 5 Posts ]
Jump to:   


Style:  
Search: