Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: How to "drop" scores?

  1. #1
    Member
    Join Date
    Mar 2011
    Posts
    66
    My Mood
    Relaxed
    Thanks
    12
    Thanked 4 Times in 4 Posts

    Default 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:
    import java.io.*;
    public class HW8 
    {
    	public static void main(String args[]) throws IOException
    	{
    	    BufferedReader keybd = new BufferedReader(new InputStreamReader(System.in));
     
    	    double[] score = new double[31];
    	    double[] max = new double[31];
     
    	    System.out.println("Enter the amount of assignments: ");
    	    int numAssign = Integer.parseInt(keybd.readLine());
     
    	    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) + ": ");
    	    	score[i] = Double.parseDouble(keybd.readLine());
     
    	    	if (score[i] < 0)
    	    		{
    	    			score[i] = 0;
    	    		}
     
    	    	System.out.print("Enter max score #" + (i) + ": ");
    	    	max[i] = Double.parseDouble(keybd.readLine());
     
    	    	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!


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: How to "drop" scores?

    Quote Originally Posted by Actinistia View Post
    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.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Mar 2011
    Posts
    66
    My Mood
    Relaxed
    Thanks
    12
    Thanked 4 Times in 4 Posts

    Default Re: How to "drop" scores?

    Quote Originally Posted by KevinWorkman View Post
    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.
    	    	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?
    Last edited by Actinistia; May 10th, 2011 at 02:20 PM.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default 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.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. The Following User Says Thank You to KevinWorkman For This Useful Post:

    Actinistia (May 11th, 2011)

  6. #5
    Member
    Join Date
    Mar 2011
    Posts
    66
    My Mood
    Relaxed
    Thanks
    12
    Thanked 4 Times in 4 Posts

    Default Re: How to "drop" scores?

    Quote Originally Posted by KevinWorkman View Post
    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!

  7. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: How to "drop" scores?

    Quote Originally Posted by Actinistia View Post
    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.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. [SOLVED] "Grade Drop 101" - Should I use an array?
    By Actinistia in forum Java Theory & Questions
    Replies: 2
    Last Post: May 5th, 2011, 11:20 AM
  2. Replies: 6
    Last Post: November 12th, 2010, 04:40 AM
  3. Java says:"Hello World". I say:"It works!"
    By Davidovic in forum Member Introductions
    Replies: 4
    Last Post: June 29th, 2010, 07:13 AM
  4. Replies: 1
    Last Post: March 31st, 2010, 09:42 PM
  5. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM