Grade Curve Array Program Problem

  • (2 Pages)
  • +
  • 1
  • 2

25 Replies - 2995 Views - Last Post: 21 April 2010 - 06:05 PM Rate Topic: -----

#1 JavaBunny  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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 class GradeCurveArray
{
	public status void main (String[] args)
	{ // Output Grade Array
	int [] gradesArray = {95, 79, 89, 78, 82};
	outputGrades(gradesArray);
	System.out.println( "Initial Grades:\n");
	System.out.printf("%s%10s", "Student", " Initial Grade");
	for (int student  = 0; student < grades.length; student++)
	system.out.printf("Student %2d", student+1);
	
	//call method getMaximum
	System.out.printf ("\n%s %d\n%s %d\n\n", "Highest Grade Is", getMaximum(gradesArray));
	}//end main

	public static int getMaximum(int grades [])
	{
	int highGrade = grades [0];
	for (int[] studentGrades : grades)
	{		
	for (int grade ; studentGrades)
	{
	if (grade > highGrade)
	highGrade = grade;
	}//end inner for
	}//end outer for
	return highGrade; //return the highest grade
	}//end Method getMaximum

	modifyArray (array); //pass array reference	

	//Add Grade Curve amount to array elements
	public static void modifyArray( int [] arrayC)
	{
	int curveGrade = C
	C=100-highGrade
	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  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1010
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 JavaBunny  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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?

View Postjapanir, 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

Was This Post Helpful? 0
  • +
  • -

#4 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 292
  • View blog
  • 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++)



because you want to use the length of your array gradesArray[]

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

Was This Post Helpful? 0
  • +
  • -

#5 JavaBunny  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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']
Was This Post Helpful? 0
  • +
  • -

#6 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 292
  • View blog
  • Posts: 1,146
  • Joined: 31-August 09

Re: Grade Curve Array Program Problem

Posted 11 April 2010 - 12:52 PM

So what errors remain?
Was This Post Helpful? 0
  • +
  • -

#7 JavaBunny  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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.

View PostLuckless, on 11 April 2010 - 12:52 PM, said:

So what errors remain?

Was This Post Helpful? 0
  • +
  • -

#8 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 292
  • View blog
  • 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 ++){
arrayC[i] += amountToAdd;
}


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

Was This Post Helpful? 1
  • +
  • -

#9 JavaBunny  Icon User is offline

  • New D.I.C Head

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

Re: Grade Curve Array Program Problem

Posted 11 April 2010 - 06:12 PM

Thank you. Should I just call arrayC gradesArray instead?

View PostLuckless, on 11 April 2010 - 01:10 PM, said:

int amountToAdd = 100- getMaximum(gradesArray) ;

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


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.

Was This Post Helpful? 0
  • +
  • -

#10 JavaBunny  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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 class GradeCurveArray
{
	
	public static void main (String[] args)
	{ // Output Grade Array
	int [] gradesArray = {95, 79, 89, 78, 82};
	outputGrades(gradesArray);
	System.out.println( "Initial Grades:\n");
	System.out.printf("%s%10s", "Student", "Initial Grade");
	for (int student  = 0; student < gradesArray.length; student++)
	system.out.printf("Student %2d", student+1);
	modifyArray (array);//pass array reference
	//call method getMaximum
	System.out.printf ("\n%s %d\n%s %d\n\n", "Highest Grade Is", getMaximum(gradesArray));
	}//end main

	public static int getMaximum(int grades [])
	{
	int highGrade = grades [0];
	for (int[] studentGrades : grades)
	{		
	for (int grade : studentGrades)
	{
	if (grade > highGrade)
	highGrade = grade;
	}//end inner for
	}//end outer for
	return highGrade; //return the highest grade
	}//end Method getMaximum

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

	{//output final grade array
	outputGrades(gradesArray);
	System.out.println("Final Grades:\n");
	System.out.printf("%s%10s", "Student", "Final Grade");
	for (int student  = 0; student < gradesArray.length; student++)
	system.out.printf("Student %2d", student+1);
	}//end main
}//end class GradeCurveArray

[quote name='Theresa Schultz' date='11 April 2010 - 06:12 PM' timestamp='1271034762' post='986790']
Was This Post Helpful? 0
  • +
  • -

#11 citus  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • 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)
        {               
            for (int grade : studentGrades)
            {
                if (grade > highGrade)
                highGrade = grade;
            }//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 [])
        {
        int highGrade = grades [0];
        for (int iterate : grades)
        {
                if (iterate > highGrade)
                {
                    highGrade = iterate;
                }
        }//end outer for
        return highGrade; //return the highest grade
        }//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)
        {
        int amountToAdd = 100- getMaximum(gradesArray);
        for (int i=0; i < arrayC.length; i ++)
        {
        arrayC[i] += amountToAdd;
        }//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



        {//output final grade array
        outputGrades(gradesArray);
        System.out.println("Final Grades:\n");
        System.out.printf("%s%10s", "Student", "Final Grade");
        for (int student  = 0; student < gradesArray.length; student++)
        system.out.printf("Student %2d", student+1);
        }//end main
}//end class GradeCurveArray


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

Was This Post Helpful? 0
  • +
  • -

#12 JavaBunny  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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 class GradeCurveArray
{
    
    public static void main (String[] args)
    { // Output Grade Array
        int [] gradesArray = {95, 79, 89, 78, 82};
        outputGrades(gradesArray);
        System.out.println( "Initial Grades:\n");
        System.out.printf("%s%10s", "Student", "Initial Grade");

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

        modifyArray (array);//pass array reference
        
        System.out.printf ("\n%s %d\n%s %d\n\n", "Highest Grade Is", getMaximum(gradesArray));
    }//end main

    public static int getMaximum(int grades [])
    {//assume first element of grades array is largest
        int highGrade = grades [0];
        //loop through grades array
        for (int[] studentGrades : grade)
        {
            
            if (grade > highGrade)
                highGrade = grade;
            
        }//end outer for
    
        return highGrade; //return the highest grade
    }//end Method getMaximum

    //Add Grade Curve amount to array elements
    public static void modifyArray( int [] gradesArray)
    {
        int amountToAdd = 100- getMaximum(gradesArray);

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

    }//end method modifyArray


    public static void outputGrades(int [] gradesArray)
    {
        //output final grade array
        outputGrades(gradesArray);
        System.out.println("Final Grades:\n");
        System.out.printf("%s%10s", "Student", "Final Grade");

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

    }//end method outputGrades

  }//end main
}//end class GradeCurveArray

Was This Post Helpful? 0
  • +
  • -

#13 pbl  Icon User is offline

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

Reputation: 8332
  • View blog
  • Posts: 31,857
  • 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

modifyArray (gradesArray);//pass array reference

for (int[] studentGrades : grade)

should probably be

for (int studentGrades : grades)
Was This Post Helpful? 1
  • +
  • -

#14 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2872
  • View blog
  • Posts: 11,031
  • 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.
Was This Post Helpful? 1
  • +
  • -

#15 JavaBunny  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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 class GradeCurveArray
{
    
    public static void main (String[] args)
    { // Output Grade Array
        int [] gradesArray = {95, 79, 89, 78, 82};
        outputGrades(gradesArray);
        System.out.println( "Initial Grades:\n");
        System.out.printf("%s%10s", "Student", "Initial Grade");

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

        modifyArray (gradesArray);//pass array reference
        
        System.out.printf ("\n%s %d\n%s %d\n\n", "Highest Grade Is", getMaximum(gradesArray));
    }//end main

    public static int getMaximum(int grades [])
    {//assume first element of grades array is largest
        int highGrade = grades [0];
        //loop through grades array
        for (int studentGrades : grades)
        {
            
            if (grade > highGrade)
                highGrade = grade;
            
        }//end outer for
    
        return highGrade; //return the highest grade
    }//end Method getMaximum

    //Add Grade Curve amount to array elements
    public static void modifyArray( int [] gradesArray)
    {
        int amountToAdd = 100- getMaximum(gradesArray);

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

    }//end method modifyArray


    public static void outputGrades(int [] gradesArray)
    {
        //output final grade array
        outputGrades(gradesArray);
        System.out.println("Final Grades:\n");
        System.out.printf("%s%10s", "Student", "Final Grade");

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

    }//end method outputGrades

}//end class GradeCurveArray

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2