# Average Test scores using arrays and methods

Page 1 of 1

## 4 Replies - 12624 Views - Last Post: 18 November 2009 - 01:30 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=139986&amp;s=ac11a5eace52f3f2ccd875145ab642d7&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 aeemma

Reputation: 0
• Posts: 7
• Joined: 18-November 09

# Average Test scores using arrays and methods

Posted 18 November 2009 - 12:40 PM

The purpose is to calculate a student's test score average in the class and sum of the total score after the scores have been adjusted. Need to create a program that reads in 12 test scores between 0 and 10 (use an array). Also need to adjust these scores by 12 values (do this by creating a method). After the test scores have been adjusted the 2 lowest scores need to be removed before calculating the student's average test score and total score (a method must be used for this part).

This is the code that I have so far but I am having issues with the main method, and how to sum the arrays..... please help thank you.

// Main Method
public static void main(String args[]){

AssignValues(); // The Assign Values method is called.
totalQuizScore =
System.out.println(totalQuizscore+" is the student's quiz score.");

}

// Method for assigning the values
public static void AssignValues(){
for(int i=0; i<number_of_quizscores; i++){
//Prompt user to enter the test scores up to 12
System.out.println("Enter a test score between 0 and 10: ");
quizscores_array[i] = myScanner.nextInt();
}
//Prompt user to enter the adjustment scores up to 12
System.out.println("Enter a test score between 0 and 10: ");
}

}
// Method for calculating the adjusted quiz scores

// make an new empty list

// make a new array after adjusting the scores

for (int k = 0; k < newAdjustedScores.size(); k++) {
}
return set;
}

public static int removeTwoLowest() {
int firstLow = -1;
int secondLow = -1;
int count = 0;

// check which student has the first low score
secondLow = firstLow;

}
else if (newAdjustedScores < secondLow) {
}
count++;
}

}
}

Is This A Good Question/Topic? 0

## Replies To: Average Test scores using arrays and methods

### #2 Dogstopper

Reputation: 2876
• Posts: 11,050
• Joined: 15-July 08

## Re: Average Test scores using arrays and methods

Posted 18 November 2009 - 12:50 PM

For future reference: Thank you.

```// Main Method
public static void main(String args[]){

AssignValues(); // The Assign Values method is called.
totalQuizScore =
System.out.println(totalQuizscore+" is the student's quiz score.");

```

You call AssignValues, which is is ok. The next line you have an invalid steament.
```totalquizScore = 0;
```

Would be far more viable of a solution.
On the next line, you print out a variable but because none of the other methods have been called (like newAdjustedQuizScores() and removeTwoLowest() are never used), then there is no valid number for the output to output

This post has been edited by Dogstopper: 18 November 2009 - 12:52 PM

### #3 aeemma

Reputation: 0
• Posts: 7
• Joined: 18-November 09

## Re: Average Test scores using arrays and methods

Posted 18 November 2009 - 01:07 PM

Dogstopper, on 18 Nov, 2009 - 11:50 AM, said:

For future reference: Thank you.

```// Main Method
public static void main(String args[]){

AssignValues(); // The Assign Values method is called.
totalQuizScore =
System.out.println(totalQuizscore+" is the student's quiz score.");

```

You call AssignValues, which is is ok. The next line you have an invalid steament.
```totalquizScore = 0;
```

Would be far more viable of a solution.
On the next line, you print out a variable but because none of the other methods have been called (like newAdjustedQuizScores() and removeTwoLowest() are never used), then there is no valid number for the output to output

``` import java.util.Scanner;
class ComputeTotalQuizScore{

// Declaring Variables
static int number_of_quizscores = 12;
static int[] quizscores_array = new int[number_of_quizscores];
static Scanner myScanner = new Scanner(System.in);

// Main Method
public static void main(String args[]){

AssignValues(); // The Assign Values method is called.
removeTwoLowest(); // method is called
totalQuizScore = 0;
System.out.println(totalQuizscore+" is the student's quiz score.");

}

// Method for assigning the values
public static void AssignValues(){
for(int i=0; i<number_of_quizscores; i++){
//Prompt user to enter the test scores up to 12
System.out.println("Enter a test score between 0 and 10: ");
quizscores_array[i] = myScanner.nextInt();
}
//Prompt user to enter the adjustment scores up to 12
System.out.println("Enter a test score between 0 and 10: ");
}

}
// Method for calculating the adjusted quiz scores

// make an new empty list

// make a new array after adjusting the scores

for (int k = 0; k < newAdjustedScores.size(); k++) {
}
return scores;
}

public static int removeTwoLowest() {
int firstLow = -1;
int secondLow = -1;
int count = 0;

// check which student has the first low score
secondLow = firstLow;

}
else if (newAdjustedScores < secondLow) {
}
count++;
}

}

```

aeemma, on 18 Nov, 2009 - 12:04 PM, said:

Dogstopper, on 18 Nov, 2009 - 11:50 AM, said:

For future reference: Thank you.

```// Main Method
public static void main(String args[]){

AssignValues(); // The Assign Values method is called.
totalQuizScore =
System.out.println(totalQuizscore+" is the student's quiz score.");

```

You call AssignValues, which is is ok. The next line you have an invalid steament.
```totalquizScore = 0;
```

Would be far more viable of a solution.
On the next line, you print out a variable but because none of the other methods have been called (like newAdjustedQuizScores() and removeTwoLowest() are never used), then there is no valid number for the output to output

``` import java.util.Scanner;
class ComputeTotalQuizScore{

// Declaring Variables
static int number_of_quizscores = 12;
static int[] quizscores_array = new int[number_of_quizscores];
static Scanner myScanner = new Scanner(System.in);

// Main Method
public static void main(String args[]){

AssignValues(); // The Assign Values method is called.
removeTwoLowest(); // method is called
totalQuizScore = 0;
System.out.println(totalQuizscore+" is the student's quiz score.");

}

// Method for assigning the values
public static void AssignValues(){
for(int i=0; i<number_of_quizscores; i++){
//Prompt user to enter the test scores up to 12
System.out.println("Enter a test score between 0 and 10: ");
quizscores_array[i] = myScanner.nextInt();
}
//Prompt user to enter the adjustment scores up to 12
System.out.println("Enter a test score between 0 and 10: ");
}

}
// Method for calculating the adjusted quiz scores

// make an new empty list

// make a new array after adjusting the scores

for (int k = 0; k < newAdjustedScores.size(); k++) {
}
return scores;
}

public static int removeTwoLowest() {
int firstLow = -1;
int secondLow = -1;
int count = 0;

// check which student has the first low score
secondLow = firstLow;

}
else if (newAdjustedScores < secondLow) {
}
count++;
}

}

```

I made the suggestions you made but I am still getting errors and don't see where the problem is. Please point out where if you can. Thank you.

### #4 Dogstopper

Reputation: 2876
• Posts: 11,050
• Joined: 15-July 08

## Re: Average Test scores using arrays and methods

Posted 18 November 2009 - 01:16 PM

Look at the compiler errors.
#1 error:
The compiler tells you that totalQuizScore has not been defined. It needs to defined as an int. Although with your code, I don't see the purpose of it, as it will always print 0.

#2 error:
```import java.util.ArrayList;

```

#3 error:
This line that you wrote:
```int newAdjustedScores = quizscores_array[i]+ adjustmentvalues_array[j];

```

The i and j that you are attempting to reference are no longer there, after the end of the AssignValues() method, they were destroyed.

# 4:
```sscores[k] = newAdjustedScores.get(k);

```

||
V
```scores[k] = newAdjustedScores.get(k);

```

# 5:
public static int newAdjustedQuizScores() returns an int, you are attempting to return an array of ints.

# 6:
public static int removeTwoLowest() { : you have no return statement. Either make it return something or declare it void, not int.

that is just the extent of compiler errors. Fix those and then truly think about the way to make it work.

### #5 aeemma

Reputation: 0
• Posts: 7
• Joined: 18-November 09

## Re: Average Test scores using arrays and methods

Posted 18 November 2009 - 01:30 PM

Dogstopper, on 18 Nov, 2009 - 12:16 PM, said:

Look at the compiler errors.
#1 error:
The compiler tells you that totalQuizScore has not been defined. It needs to defined as an int. Although with your code, I don't see the purpose of it, as it will always print 0.

#2 error:
```import java.util.ArrayList;

```

#3 error:
This line that you wrote:
```int newAdjustedScores = quizscores_array[i]+ adjustmentvalues_array[j];

```

The i and j that you are attempting to reference are no longer there, after the end of the AssignValues() method, they were destroyed.

# 4:
```sscores[k] = newAdjustedScores.get(k);

```

||
V
```scores[k] = newAdjustedScores.get(k);

```

# 5:
public static int newAdjustedQuizScores() returns an int, you are attempting to return an array of ints.

# 6:
public static int removeTwoLowest() { : you have no return statement. Either make it return something or declare it void, not int.

that is just the extent of compiler errors. Fix those and then truly think about the way to make it work.

Ok I will keep trying to figure it out thank you for your input.