# How to "drop" scores?

• May 10th, 2011, 01:42 PM
Actinistia
How to "drop" scores?
Hello everyone, I was trying to create a program that allows the user to input 4-30 assignment scores/max scores and drop 3 scores to output the best percentage. The exact requirements can be found in my other thread: http://www.javaprogrammingforums.com...use-array.html

I ended up using an array to store the score and max score separately. My problem at this point is trying to come up with a way to drop 3 scores.

My code at this point is:
Code java:

import java.io.*;
public class HW8
{
public static void main(String args[]) throws IOException
{

double[] score = new double[31];
double[] max = new double[31];

System.out.println("Enter the amount of assignments: ");

if (numAssign < 4)
{
numAssign = 4;
}
else if (numAssign > 30)
{
numAssign = 30;
}

double result = 0.0;
double result2 = 0.0;

for (int i = 1; i <= numAssign; i++)
{
System.out.print("Enter student's score #" + (i) + ": ");

if (score[i] < 0)
{
score[i] = 0;
}

System.out.print("Enter max score #" + (i) + ": ");

if (max[i] < 1)
{
max[i] = 1;
}
else if (max[i] > 100)
{
max[i] = 100;
}
if (score[i] > max[i])
{
score[i] = max[i];
}

result = result + score[i];
result2 = result2 + max[i];
}	// ends for loop
System.out.println("Original percentage: " + (result/result2)*100.0 + "%");
}	// ends main

}		// ends class

I was thinking about using if/else conditions but that wouldn't really limit the amount dropped to 3. Any advice is appreciated!
• May 10th, 2011, 01:44 PM
KevinWorkman
Re: How to "drop" scores?
Quote:

Originally Posted by Actinistia
I was thinking about using if/else conditions but that wouldn't really limit the amount dropped to 3. Any advice is appreciated!

It would if you kept track of how many you dropped so far.
• May 10th, 2011, 01:52 PM
Actinistia
Re: How to "drop" scores?
Quote:

Originally Posted by KevinWorkman
It would if you kept track of how many you dropped so far.

Why didn't I just think about that! Thanks, I'll try creating a counter to keep track of it and see how it works.

*edit* Would something like this work? Ignoring the first part of the condition (since I'm still trying to figure out how to create the "best" percentage). I placed this within the for loop after the last if condition and before the results.
Code java:

if ((score[i] > (max[i]/2)) && (counter <= 3));          // Suppose to allow 3 inputs to be "dropped" or turn inputted value to 0
{
score[i] = 0;
max[i] = 0;
counter++;
}

*edit2* I was just going over this condition and I think I messed up because now it makes each of array elements to 0. But would this be somewhere along the lines of what I should do?
• May 11th, 2011, 07:26 AM
KevinWorkman
Re: How to "drop" scores?
Something along the lines, sure. But I can't really tell you much else, since we don't know what is in the score array or the max array, or even what the program is supposed to actually do. Keeping track of the count like that is probably the way to go though.
• May 11th, 2011, 08:18 AM
Actinistia
Re: How to "drop" scores?
Quote:

Originally Posted by KevinWorkman
Something along the lines, sure. But I can't really tell you much else, since we don't know what is in the score array or the max array, or even what the program is supposed to actually do. Keeping track of the count like that is probably the way to go though.

Thanks for the previous suggestion! In my first post, I gave a link to another thread I made which had the actual requirements of the program on it. Basically the program is suppose to create the best possible percentage for a student by dropping 3 assignment scores. The score array and max array each store a score (e.g. 35 out of 40 possible points, score[i] stores the 35 and max[i] stores the 40). I had thought about putting them both into an array having the score and max alternate but wasn't sure if it was better to do. I felt that working with 2 separate arrays was easier to work with. Anyways, thanks again!
• May 11th, 2011, 09:00 AM
KevinWorkman
Re: How to "drop" scores?
Quote:

Originally Posted by Actinistia
Thanks for the previous suggestion! In my first post, I gave a link to another thread I made which had the actual requirements of the program on it. Basically the program is suppose to create the best possible percentage for a student by dropping 3 assignment scores. The score array and max array each store a score (e.g. 35 out of 40 possible points, score[i] stores the 35 and max[i] stores the 40). I had thought about putting them both into an array having the score and max alternate but wasn't sure if it was better to do. I felt that working with 2 separate arrays was easier to work with. Anyways, thanks again!

Well, do whatever fits into your head. But just a tip- you might want to stop to think about how you'd do this "by hand" without a program. Given a stack of grades, how would you figure out which three to drop? Write out basic instructions, pretend you're writing them for a really dumb friend who needs to do this. When you have that written out, you'll have a basic algorithm that should be pretty easy to translate into code.