• Post Reply Bookmark Topic Watch Topic
  • New Topic

New average with lowest score dropped in array  RSS feed

 
Crea Smith
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Our first exercise is to find the total average of test scores in an array and that part was easy. The second exercise is to then print a new average with the lowest score dropped. Our prof specifically does not want us to use the getLowestScore method. What am I doing wrong?


if (scores [count] < lowest)

double newAverage = 0;
double newSum = 0;
double newTotal = 0;
lowest = scores[count];
newTotal = total-lowest;
newSum
newAverage = (double) newSum/newTotal;




System.out.println("The lowest score in the array is " + lowest);
System.out.println("The new average with lowest grade dropped is " + newAverage);
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about calculating the sum of all elements, then subtracting the minimum value? You then have the sum of all elements except the lowest value. If you divide this number by the number of elements - 1 you get the average with the lowest value dropped. Well, one occurrence of the lowest value anyway.

You are subtracting the minimum value at that time, which may or may not be the overall minimum. If it isn't you need to add it again, but you don't.
 
Crea Smith
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand the process. I just have no idea what java syntax to use to code it. I've tried everything I know for 7 hours and nothing.
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, what do you have so far? Show us the code: the declarations, initializations, loop, etc.
 
Crea Smith
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it all figured out now.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!