Page 1 of 1

## 3 Replies - 29730 Views - Last Post: 06 April 2010 - 07:29 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=166562&amp;s=6b8b458b90e7bd1e6f96312d300400ea&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 shantalg5

• New D.I.C Head

Reputation: 1
• Posts: 10
• Joined: 11-March 10

Posted 06 April 2010 - 07:16 PM

** THE PROBLEM that i need help with is that its not letting me insert the scores how can I insert my scores??

I'm writing a program that reads students scores, gets the best score, and then assigns grades based on
Grade is A if score is >= best - 10;
Grade is B if score is >= best - 20;
Grade is C if score is >= best - 30;
Grade is D if score is >= best - 40;
Grade is F otherwise;

Here's the sample run:

Enter the number of students: 4
Enter 4 scores: 40 55 70 58

Student 0 score is 40 and grade is C
Student 1 score is 55 and grade is B
Student 2 score is 70 and grade is A
Student 3 score is 58 and grade is B
__________
here's what I have so far:
```import java.util.Scanner;
public class assigningGrades {
/** Main method */
public static void main(String[] args) {
// Create a Scanner
Scanner input = new Scanner(System.in);
// Get number of students
System.out.print("Enter number of students: ");
int numberOfStudents = input.nextInt();

int[] scores = new int[numberOfStudents]; // Array scores
int best = 0; // The best score

// Read scores and find the best score
System.out.print("Enter " + numberOfStudents + " scores: ");

for (int i = 0; i < scores.length; i++) {
if ( scores[i] > best)
best = scores[i];

//find the highest score

}
// Declare and initialize output string
String output = "";
// Assign and display grades
for (int i = 0; i < scores.length; i++) {
if (scores[i] >= best - 10)
else if (scores[i] >= best - 20)
else if (scores[i] >= best - 30)
else if (scores[i] >= best - 40)
else

output += "Student " + i + " score is " +
scores[i] + " and grade is " + grade + "\n";
}
// Display the result
System.out.println(output);
}
}
```

Is This A Good Question/Topic? 1

## Replies To: assigning grades

### #2 erik.price

• D.I.C Lover

Reputation: 486
• Posts: 2,690
• Joined: 18-December 08

## Re: assigning grades

Posted 06 April 2010 - 07:20 PM

You never use your Scanner to get the numberOfStudents grade inputs.

Try putting a for loop to read in the values after this line: System.out.print("Enter " + numberOfStudents + " scores: ");

```for(int i = 0; i < numberOfStudents; i++){
//get int value from Scanner.
//store it in scores[i]
}
```

This post has been edited by erik.price: 06 April 2010 - 07:20 PM

### #3 japanir

• jaVanir

Reputation: 1013
• Posts: 3,025
• Joined: 20-August 09

## Re: assigning grades

Posted 06 April 2010 - 07:21 PM

use a for loop to iterate the number of scores you want to insert, and for each iteration get an int value using the scanner Object, and assign it to the current index of the loop:
```for(int i = 0 ; i < scores.length;i++){
scores[i] = input.nextInt();
}
```

edit, ninjad by erik.price

This post has been edited by japanir: 06 April 2010 - 07:22 PM

### #4 pdkharkar

• D.I.C Regular

Reputation: 65
• Posts: 345
• Joined: 19-January 09

## Re: assigning grades

Posted 06 April 2010 - 07:29 PM

you are not entering the scores in the array elements
try this
```System.out.print("Enter " + numberOfStudents + " scores: ");
for (int i = 0; i < scores.length ; i++  ){
System.out.println("Enter the score");
scores[i] = input.nextInt();
}
```

and I want to suggest some java naming standards ,the convention is called as camelCase style
for class name, it should always start with a Capital letter and if you want to join two names, then the first name of should be capital in your example write like AssigningGrades
for methods and variables, start with small letter and if there is another word then capitalize the first letter of second word like methodName

This post has been edited by pdkharkar: 06 April 2010 - 07:31 PM