Results 1 to 14 of 14
  1. #1
    rochla16 is offline Member
    Join Date
    Mar 2011
    Posts
    16
    Rep Power
    0

    Default Project with Arrays and Grades

    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.

    For each grade:
    Find the location of the letter grade in the letter_grades table.
    The numeric equivalent is in the grades table.
    Total the numeric equivalent values.

    After all grades processed:
    Compute the grade point average.
    Look up the equivalent letter grade using another loop.

    For loops will work.

    The output should look like this:

    Average: 0.7140000000000001
    Grade: C-

    public class Project2 {
    public static void main(String[] args) {
    String[] letter_grades = new String[12];
    double[] grades = new double[12];
    letter_grades[0] = "A";
    letter_grades[1] = "A-";
    letter_grades[2] = "B+";
    letter_grades[3] = "B";
    letter_grades[4] = "B-";
    letter_grades[5] = "C+";
    letter_grades[6] = "C";
    letter_grades[7] = "C-";
    letter_grades[8] = "D+";
    letter_grades[9] = "D";
    letter_grades[10] = "D-";
    letter_grades[11] = "F";
    grades[0] = .93;
    grades[1] = .90;
    grades[2] = .87;
    grades[3] = .83;
    grades[4] = .80;
    grades[5] = .77;
    grades[6] = .73;
    grades[7] = .70;
    grades[8] = .67;
    grades[9] = .63;
    grades[10] = .60;
    grades[11] = .0;
    String[] grades_entered = new String[10];
    grades_entered[0] = "B";
    grades_entered[1] = "C+";
    grades_entered[2] = "D-";
    grades_entered[3] = "C+";
    grades_entered[4] = "D-";

    //Your code goes here

    }
    }

  2. #2
    FlipPoker@gmail.com is offline Senior Member
    Join Date
    Mar 2011
    Posts
    104
    Rep Power
    0

    Default

    Here's some pseudocode to get you started...
    Java 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

  3. #3
    rochla16 is offline Member
    Join Date
    Mar 2011
    Posts
    16
    Rep Power
    0

    Default

    thanks! i'll see what i can come up with, with that!

  4. #4
    rochla16 is offline Member
    Join Date
    Mar 2011
    Posts
    16
    Rep Power
    0

    Default

    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) {
    String[] letter_grades = new String[12];
    double[] grades = new double[12];
    letter_grades[0] = "A";
    letter_grades[1] = "A-";
    letter_grades[2] = "B+";
    letter_grades[3] = "B";
    letter_grades[4] = "B-";
    letter_grades[5] = "C+";
    letter_grades[6] = "C";
    letter_grades[7] = "C-";
    letter_grades[8] = "D+";
    letter_grades[9] = "D";
    letter_grades[10] = "D-";
    letter_grades[11] = "F";
    grades[0] = .93;
    grades[1] = .90;
    grades[2] = .87;
    grades[3] = .83;
    grades[4] = .80;
    grades[5] = .77;
    grades[6] = .73;
    grades[7] = .70;
    grades[8] = .67;
    grades[9] = .63;
    grades[10] = .60;
    grades[11] = .0;
    String[] grades_entered = new String[10];
    grades_entered[0] = "B";
    grades_entered[1] = "C+";
    grades_entered[2] = "D-";
    grades_entered[3] = "C+";
    grades_entered[4] = "D-";

    //Your code goes here
    for (int i=0; grades_entered.length; i++);{
    for (int j=0; letter_grades.length; i++);
    if (grades_entered==letter_grades);
    System.out.println ("Grades " + i);
    System.out.println (strings[i] + " (" + strings[i].length() + " characters)");
    {
    for (int x=total grades);
    if (total grades/grades_entered)
    System.out.println (total grades/grades_entered);

    if (grades > .93)
    System.out.println ("letter_grades[0]);
    if (grades > .90)
    System.out.println ("letter_grades[1]);
    if (grades > .87)
    System.out.println ("letter_grades[2]);
    if (grades > .83)
    System.out.println ("letter_grades[3]);
    if (grades > .80)
    System.out.println ("letter_grades[4]);
    if (grades > .77)
    System.out.println ("letter_grades[5]);
    if (grades > .73)
    System.out.println ("letter_grades[6]);
    if (grades > .70)
    System.out.println ("letter_grades[7]);
    if (grades > .67)
    System.out.println ("letter_grades[8]);
    if (grades > .63)
    System.out.println ("letter_grades[9]);
    if (grades > .60)
    System.out.println ("letter_grades[10]);
    if (grades > .0)
    System.out.println ("letter_grades[11]);
    }
    }

  5. #5
    FlipPoker@gmail.com is offline Senior Member
    Join Date
    Mar 2011
    Posts
    104
    Rep Power
    0

    Default

    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. #6
    rochla16 is offline Member
    Join Date
    Mar 2011
    Posts
    16
    Rep Power
    0

    Default

    i guess i dont even know where to start..

  7. #7
    FlipPoker@gmail.com is offline Senior Member
    Join Date
    Mar 2011
    Posts
    104
    Rep Power
    0

    Default

    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. #8
    rochla16 is offline Member
    Join Date
    Mar 2011
    Posts
    16
    Rep Power
    0

    Default

    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. #9
    FlipPoker@gmail.com is offline Senior Member
    Join Date
    Mar 2011
    Posts
    104
    Rep Power
    0

    Default

    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. #10
    rochla16 is offline Member
    Join Date
    Mar 2011
    Posts
    16
    Rep Power
    0

    Default

    hm, not getting it to work..

    for (int i=0; grades_entered.length; i++)
    {
    for (int j=0; letter_grades.length; i++)
    {
    if (grades_entered==letter_grades);
    grades[0]=letter_grades[0];
    grades[1]=letter_grades[1];
    grades[2]=letter_grades[2];
    grades[3]=letter_grades[3];
    grades[4]=letter_grades[4];
    grades[5]=letter_grades[5];
    grades[6]=letter_grades[6];
    grades[7]=letter_grades[7];
    grades[8]=letter_grades[8];
    grades[9]=letter_grades[9];
    grades[10]=letter_grades[10];
    grades[11]=letter_grades[11];

    System.out.println("Grade" + letter_grade);

    }
    }

  11. #11
    rochla16 is offline Member
    Join Date
    Mar 2011
    Posts
    16
    Rep Power
    0

    Default

    it keeps saying "found int but expected boolean"

  12. #12
    FlipPoker@gmail.com is offline Senior Member
    Join Date
    Mar 2011
    Posts
    104
    Rep Power
    0

    Default

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

    Default

    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. #14
    rochla16 is offline Member
    Join Date
    Mar 2011
    Posts
    16
    Rep Power
    0

    Default

    public class Project3 {
    public static void main(String[] args) {
    String[] letter_grades = new String[12];
    double[] grades = new double[12];
    letter_grades[0] = "A";
    letter_grades[1] = "A-";
    letter_grades[2] = "B+";
    letter_grades[3] = "B";
    letter_grades[4] = "B-";
    letter_grades[5] = "C+";
    letter_grades[6] = "C";
    letter_grades[7] = "C-";
    letter_grades[8] = "D+";
    letter_grades[9] = "D";
    letter_grades[10] = "D-";
    letter_grades[11] = "F";
    grades[0] = .93;
    grades[1] = .90;
    grades[2] = .87;
    grades[3] = .83;
    grades[4] = .80;
    grades[5] = .77;
    grades[6] = .73;
    grades[7] = .70;
    grades[8] = .67;
    grades[9] = .63;
    grades[10] = .60;
    grades[11] = .0;
    String[] grades_entered = new String[10];
    grades_entered[0] = "B";
    grades_entered[1] = "C+";
    grades_entered[2] = "D-";
    grades_entered[3] = "C+";
    grades_entered[4] = "D-";
    {
    for (int i=0; grades_entered.length; i++){
    for (int j=0; letter_grades.length; j++){


    if (grades_entered[i]==letter_grades[j]);
    grades[0]=letter_grades[0];
    grades[1]=letter_grades[1];
    grades[2]=letter_grades[2];
    grades[3]=letter_grades[3];
    grades[4]=letter_grades[4];
    grades[5]=letter_grades[5];
    grades[6]=letter_grades[6];
    grades[7]=letter_grades[7];
    grades[8]=letter_grades[8];
    grades[9]=letter_grades[9];
    grades[10]=letter_grades[10];
    grades[11]=letter_grades[11];

    System.out.println("Grade" + letter_grades[j]);
    }

    average=((total grades)/(grades_entered));
    System.out.println ("Average grades=" + average);

    }
    }

Similar Threads

  1. Arrays.sort... why sorting all arrays in class?
    By innspiron in forum New To Java
    Replies: 6
    Last Post: 03-23-2010, 01:40 AM
  2. New project, need some help :( (arrays)
    By Isshin in forum New To Java
    Replies: 0
    Last Post: 03-21-2010, 10:51 PM
  3. calculate average letter grades...
    By Christ90 in forum New To Java
    Replies: 14
    Last Post: 01-25-2010, 12:59 AM
  4. Array help counting # of grades
    By speaknspell in forum New To Java
    Replies: 4
    Last Post: 04-16-2009, 10:09 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •