# Project with Arrays and Grades

• 03-24-2011, 07:54 PM
rochla16
I'm having trouble with this project for Java. :confused: Any help would be really great!!:)

These are the instructions:

You are not to modify any code provided. The program is to compute the average of several grades and find the letter grade equivalent. All the grades are in the grades table. The program is to process any number of grades in the table without the user entering anything. The program is to use two loops which are nested.

The numeric equivalent is in the grades table.
Total the numeric equivalent values.

Look up the equivalent letter grade using another loop.

For loops will work.

The output should look like this:

Average: 0.7140000000000001

public class Project2 {
public static void main(String[] args) {

}
}
• 03-24-2011, 08:15 PM
FlipPoker@gmail.com
Here's some pseudocode to get you started...
Code:

```For each entered grade     For each letter grade         if the entered grade equals the letter grade             save the array index             get the numerical grade value using the array index             exit the For loop         end if     End For     add this grade's numerical value to the total End For Divide the grade total by the number of entered grades to get the average For each grade value     if the grade value is equivalent to the average grade         save the array index         get the letter grade equivalent using the array index         exit the For loop     end if End For Display the numerical grade average Display the letter grade equivalent of the average```
• 03-24-2011, 08:20 PM
rochla16
thanks! i'll see what i can come up with, with that!
• 03-24-2011, 11:38 PM
rochla16
I'm getting lost now :/ Any suggestions on where to go and how to fix this?

public class Project2 {
public static void main(String[] args) {

System.out.println (strings[i] + " (" + strings[i].length() + " characters)");
{

}
}
• 03-24-2011, 11:45 PM
FlipPoker@gmail.com
The syntax of your for loops is wrong. You should review for loops in your text. A typical for loop looks like this (note how curly braces indicate the block of statements that are repeated):
Code:

```for (int i=0; i < 10; i++) {     //statements in here are repeated     System.out.println(i); }```
• 03-25-2011, 12:08 AM
rochla16
i guess i dont even know where to start..
• 03-25-2011, 12:17 AM
FlipPoker@gmail.com
A for loop is used to repeat a block of statements. In the pseudocode above, there is a for loop within a for loop. That's what is meant by "nested". A for loop is a statement, just like any other statement. So you can include a for loop inside a for loop. It would repeat just like any other statement in the for loop block.

I suggest you study the pseudocode that I posted above. Try to understand what you need to do in plain English. Pay close attention to the sequence of statements. Notice how certain things repeat.

Once you understand the logic, you can directly translate it to real code.
• 03-25-2011, 12:34 AM
rochla16
so starting off like this?

for (int i=0; i < grades_entered.length; i++)
{
System.out.println(i);
for (int j=0; j< letter_grades.length; i++)
{
System.out.println(j);
}
• 03-25-2011, 12:38 AM
FlipPoker@gmail.com
The println() statement was just an example. I suggest starting small. Continue with the nested loop that you started and see if you can get it to work. Once you get that simple nested loop working, add more logic to it (e.g. try accessing the different arrays and retrieve values). Slowly add more and more logic until your program is complete.
• 03-25-2011, 01:14 AM
rochla16
hm, not getting it to work..

{
{

}
}
• 03-25-2011, 01:21 AM
rochla16
it keeps saying "found int but expected boolean"
• 03-25-2011, 01:32 AM
FlipPoker@gmail.com
This is wrong:
Code:

`if (grades_entered==letter_grades);`
Those are arrays. You need to compare array values, so use the appropriate indexes:
Code:

`if (grades_entered[i]==letter_grades[j]);`
Your for loops are incorrect. Look up the syntax of for loops. A for loop is supposed to have an initialization part, comparison part, increment part, and loop block.

Also, in the second for loop, it should have j++ at the end (not i++).
• 03-29-2011, 12:26 AM
rochla16
I tried redoing some of the code based on the pseudocode. I don't know what you mean by "saving the array" and for each grade value if the grade value is equivalent to the average grade? I'm not sure how to start it?
PS, thanks for being super helpful!!
• 03-29-2011, 12:40 AM
rochla16
public class Project3 {
public static void main(String[] args) {
{