# Grade Curve Array Program Problem

• (2 Pages)
• 1
• 2

## 25 Replies - 5371 Views - Last Post: 21 April 2010 - 06:05 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=168322&amp;s=b1d8a72d89caa016b62f1159330803b8&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 JavaBunny

Reputation: 0
• Posts: 32
• Joined: 21-February 10

# Grade Curve Array Program Problem

Posted 11 April 2010 - 11:51 AM

My homework assignment is to create a program using an array so I decided to create a program that creates a grade curve but I'm stuck. I guess time off for Spring Break got to me. Here is what I have so far. Can anyone give me some hints to get me back on track? Any help would be greatly appreciated!
```//GradeCurveArray.java
{
public status void main (String[] args)
int [] gradesArray = {95, 79, 89, 78, 82};
for (int student  = 0; student < grades.length; student++)
system.out.printf("Student %2d", student+1);

//call method getMaximum
}//end main

public static int getMaximum(int grades [])
{
{
{
}//end inner for
}//end outer for
}//end Method getMaximum

modifyArray (array); //pass array reference

public static void modifyArray( int [] arrayC)
{
for (int counter=0; counter<arrayC.length; counter++)
arrayC[counter]+=C;
}//end method modifyArray
```

Is This A Good Question/Topic? 0

## Replies To: Grade Curve Array Program Problem

### #2 japanir

• jaVanir

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

## Re: Grade Curve Array Program Problem

Posted 11 April 2010 - 11:58 AM

the main method should be declared static:
```public static void main(String[] args)
```

also, you are not using the for loop correctly here:
``` for (int grade ; studentGrades)
```

should be:
``` for (int grade : studentGrades)
```

you call this method:
```modifyArray (array); //pass array reference
```

outside any method block.
perhaps it should be inside the main method?

what is C?
```int curveGrade = C
```

you have a parameter passed to that method called arrayC, but it is an array of int values, so you cannot pass it to an int variable.

did you declare the outputGrades method? you call it in the main method, but i see no implementation for it.

### #3 JavaBunny

Reputation: 0
• Posts: 32
• Joined: 21-February 10

## Re: Grade Curve Array Program Problem

Posted 11 April 2010 - 12:12 PM

Thanks. I have fixed the static method, and loop. I moved the modifyArray line here in the main method.
```system.out.printf("Student %2d", student+1);
modifyArray (array);//pass array reference
//call method getMaximum
```

Do you think that will be alright? For the question about C. I was trying to figure out how to write the code that will take the highest grade, subtract it from 100 and then add that number to all of the array values and then display them as the final grades but I just couldn't figure out how to do it for some reason. I have tried to write this program by piecing together a bunch of stuff from my book and I think that it part of what is causing my problems. Any suggestions?

japanir, on 11 April 2010 - 11:58 AM, said:

the main method should be declared static:
```public static void main(String[] args)
```

also, you are not using the for loop correctly here:
``` for (int grade ; studentGrades)
```

should be:
``` for (int grade : studentGrades)
```

you call this method:
```modifyArray (array); //pass array reference
```

outside any method block.
perhaps it should be inside the main method?

what is C?
```int curveGrade = C
```

you have a parameter passed to that method called arrayC, but it is an array of int values, so you cannot pass it to an int variable.

did you declare the outputGrades method? you call it in the main method, but i see no implementation for it.

This post has been edited by Theresa Schultz: 11 April 2010 - 06:39 PM

### #4 Luckless

• </luck>

Reputation: 293
• Posts: 1,146
• Joined: 31-August 09

## Re: Grade Curve Array Program Problem

Posted 11 April 2010 - 12:42 PM

Quote

```  for (int student  = 0; student < grades.length; student++)

```

i believe this should be:

```  for (int student  = 0; student < gradesArray.length; student++)

```

This post has been edited by Luckless: 11 April 2010 - 12:44 PM

### #5 JavaBunny

Reputation: 0
• Posts: 32
• Joined: 21-February 10

## Re: Grade Curve Array Program Problem

Posted 11 April 2010 - 12:48 PM

Thanks! I have fixed that in the code.
[quote name='Luckless' date='11 April 2010 - 12:42 PM' timestamp='1271014940' post='986543']

### #6 Luckless

• </luck>

Reputation: 293
• Posts: 1,146
• Joined: 31-August 09

## Re: Grade Curve Array Program Problem

Posted 11 April 2010 - 12:52 PM

So what errors remain?

### #7 JavaBunny

Reputation: 0
• Posts: 32
• Joined: 21-February 10

## Re: Grade Curve Array Program Problem

Posted 11 April 2010 - 01:01 PM

Unfortunately I haven't even gotten to the point of errors yet because I got stuck. The biggest block right now is the last part (modifyArray) where I am trying to figure out how to take the highGrade and subtract it from 100 and then add the difference to all of the other grades in the array and then print that list. How do I do that? I know what I have on there now is not right.

Luckless, on 11 April 2010 - 12:52 PM, said:

So what errors remain?

### #8 Luckless

• </luck>

Reputation: 293
• Posts: 1,146
• Joined: 31-August 09

## Re: Grade Curve Array Program Problem

Posted 11 April 2010 - 01:10 PM

```int amountToAdd = 100- getMaximum(gradesArray) ;

for(int i = 0; i < arrayC.length; i ++){
}

```

this takes the highest grade and subtracts it from 100 then adds amountToAdd to each index location in arrayC[](which is really gradesArray[]). Hope this helps you.

This post has been edited by Luckless: 11 April 2010 - 01:12 PM

### #9 JavaBunny

Reputation: 0
• Posts: 32
• Joined: 21-February 10

## Re: Grade Curve Array Program Problem

Posted 11 April 2010 - 06:12 PM

Luckless, on 11 April 2010 - 01:10 PM, said:

```int amountToAdd = 100- getMaximum(gradesArray) ;

for(int i = 0; i < arrayC.length; i ++){
}

```

this takes the highest grade and subtracts it from 100 then adds amountToAdd to each index location in arrayC[](which is really gradesArray[]). Hope this helps you.

### #10 JavaBunny

Reputation: 0
• Posts: 32
• Joined: 21-February 10

## Re: Grade Curve Array Program Problem

Posted 11 April 2010 - 06:25 PM

I am getting a compile error on my code. It says "Java49 reached end of file while parsing.}//end class GradeCurveArray" Please let me know what I need to fix to get this to work correctly.
```//GradeCurveArray.java

{

public static void main (String[] args)
int [] gradesArray = {95, 79, 89, 78, 82};
for (int student  = 0; student < gradesArray.length; student++)
system.out.printf("Student %2d", student+1);
modifyArray (array);//pass array reference
//call method getMaximum
}//end main

public static int getMaximum(int grades [])
{
{
{
}//end inner for
}//end outer for
}//end Method getMaximum

public static void modifyArray( int [] arrayC)
{
for (int i=0; i < arrayC.length; i ++)
{
}//end method modifyArray

for (int student  = 0; student < gradesArray.length; student++)
system.out.printf("Student %2d", student+1);
}//end main
```

[quote name='Theresa Schultz' date='11 April 2010 - 06:12 PM' timestamp='1271034762' post='986790']

### #11 citus

Reputation: 16
• Posts: 140
• Joined: 28-March 10

## Re: Grade Curve Array Program Problem

Posted 12 April 2010 - 02:21 AM

You have a number of problems.

1. You have a bunch of words spelled incorrectly. Java is a CaSe-SENsiTiVe language. Also, you left out one curly brace "}" at the bottom of your code.
```        system.out.printf("Student %2d", student+1);
//.......
system.out.printf("Student %2d", student+1);

```

Both of those should be "System" instead of "system".

2.
```        outputGrades(gradesArray);

```

Is this method (outputGrades(int[])) declared and defined in another piece of code? I don't see any declaration for it.

3.
```        modifyArray (array);//pass array reference

```

You do not define a variable named "array". Did you mean to use modifyArray(gradesArray)?

4.
```        for (int[] studentGrades : grades)
{
{
}//end inner for
}//end outer for

```

You are not using the for-each loop properly. You are trying to use an array (int[] studentGrades) which is already declared, to iterate through an array of ints (int[] grades) which is passed into the method as a parameter. Try using the below code.

```        public static int getMaximum(int grades [])
{
{
{
}
}//end outer for
}//end Method getMaximum

```

EDIT the forum messed up the last post I was trying to edit so I will try this again.

I don't know what you are trying to do with printf, but you may as well just simplify things and write a method like printMyStudentArray(int[]) which will handle printing out the numbers for you. Also please read this link for more information on the printf() method.

Lastly.
```        //Add Grade Curve amount to array elements
public static void modifyArray( int [] arrayC)
{
for (int i=0; i < arrayC.length; i ++)
{
}//end method modifyArray

//If you are trying to end the method here then you are
//missing a "}". If you do end the method here then all
//of the code below this point is outside of any method
//declared in your class. You will either need to remove
//the code or move it inside of a method for execution

for (int student  = 0; student < gradesArray.length; student++)
system.out.printf("Student %2d", student+1);
}//end main

```

This post has been edited by citus: 12 April 2010 - 02:50 AM

### #12 JavaBunny

Reputation: 0
• Posts: 32
• Joined: 21-February 10

## Re: Grade Curve Array Program Problem

Posted 15 April 2010 - 07:52 PM

I am trying to write a program that takes an array of 5 grades, finds the highest grade, subtracts the highest grade from 100 and adds the difference to the rest of the values in the array and redisplays them as the grade curve. Here is the code that I have but I get an error that says java:60: class, interface, or enum expected }//end class GradeCurveArray. Please help me fix the program so it will work.
```//GradeCurveArray.java

{

public static void main (String[] args)
int [] gradesArray = {95, 79, 89, 78, 82};

for (int student  = 0; student < gradesArray.length; student++)
System.out.printf("Student %2d", student+1);

modifyArray (array);//pass array reference

}//end main

public static int getMaximum(int grades [])
{//assume first element of grades array is largest
{

}//end outer for

}//end Method getMaximum

public static void modifyArray( int [] gradesArray)
{

for (int i=0; i < gradesArray.length; i++)

}//end method modifyArray

{

for (int student  = 0; student < gradesArray.length; student++)
System.out.printf("Student %2d", student+1);

}//end main
```

### #13 pbl

• There is nothing you can't do with a JTable

Reputation: 8378
• Posts: 31,956
• Joined: 06-March 08

## Re: Grade Curve Array Program Problem

Posted 15 April 2010 - 09:51 PM

modifyArray (array);//pass array reference

should probably be

should probably be

### #14 Dogstopper

Reputation: 2965
• Posts: 11,222
• Joined: 15-July 08

## Re: Grade Curve Array Program Problem

Posted 16 April 2010 - 03:36 AM

Ypu also have one too many ending braces at the end. Delete the one that says "end main" (At the VERY end), as you have already ended main.

### #15 JavaBunny

Reputation: 0
• Posts: 32
• Joined: 21-February 10

## Re: Grade Curve Array Program Problem

Posted 16 April 2010 - 08:14 AM

Thank you very much! I have made those changes but now I am getting two new errors. java:28: cannot find symbol. symbol:variable grade. location: class GradeCurveArray. if (grade > highGrade). It is pointing to the "g" in grade. The second error is java:29: cannot find symbol. symbol: variable grade. location: class GradeCureveArray. highGrade=grade. Pointing to the "g" in grade again. Here is the code again after I made the changes. I really appreciate the help in trying to get this to work!
``` //GradeCurveArray.java

{

public static void main (String[] args)
int [] gradesArray = {95, 79, 89, 78, 82};

for (int student  = 0; student < gradesArray.length; student++)
System.out.printf("Student %2d", student+1);

}//end main

public static int getMaximum(int grades [])
{//assume first element of grades array is largest
{

}//end outer for

}//end Method getMaximum

public static void modifyArray( int [] gradesArray)
{

for (int i=0; i < gradesArray.length; i++)

}//end method modifyArray

{

for (int student  = 0; student < gradesArray.length; student++)
System.out.printf("Student %2d", student+1);