1. Member
Join Date
Mar 2011
Posts
16
Rep Power
0

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) {

}
}

2. Member
Join Date
Mar 2011
Posts
94
Rep Power
0
Here's some pseudocode to get you started...
Java Code:
```For each entered grade
save the array index
get the numerical grade value using the array index
exit the For loop
end if
End For
End For

Divide the grade total by the number of entered grades to get the average

save the array index
get the letter grade equivalent using the array index
exit the For loop
end if
End For

Display the letter grade equivalent of the average```

3. Member
Join Date
Mar 2011
Posts
16
Rep Power
0
thanks! i'll see what i can come up with, with that!

4. Member
Join Date
Mar 2011
Posts
16
Rep Power
0
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)");
{

}
}

5. Member
Join Date
Mar 2011
Posts
94
Rep Power
0
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):
Java Code:
```for (int i=0; i < 10; i++)
{
//statements in here are repeated
System.out.println(i);

}```

6. Member
Join Date
Mar 2011
Posts
16
Rep Power
0
i guess i dont even know where to start..

7. Member
Join Date
Mar 2011
Posts
94
Rep Power
0
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.

8. Member
Join Date
Mar 2011
Posts
16
Rep Power
0
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);
}

9. Member
Join Date
Mar 2011
Posts
94
Rep Power
0
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.

10. Member
Join Date
Mar 2011
Posts
16
Rep Power
0
hm, not getting it to work..

{
{

}
}

11. Member
Join Date
Mar 2011
Posts
16
Rep Power
0
it keeps saying "found int but expected boolean"

12. Member
Join Date
Mar 2011
Posts
94
Rep Power
0
This is wrong:
Java Code:
`if (grades_entered==letter_grades);`
Those are arrays. You need to compare array values, so use the appropriate indexes:
Java 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++).

13. Member
Join Date
Mar 2011
Posts
16
Rep Power
0
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!!

14. Member
Join Date
Mar 2011
Posts
16
Rep Power
0
public class Project3 {
public static void main(String[] args) {
{

}

}
}