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 3 of 3

Thread: "Grade Drop 101" - Should I use an array?

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

    Default "Grade Drop 101" - Should I use an array?

    Hello everyone, I've been working on a new program that my professor gave us for general practice. I've gotten a bit of code with gets user input and outputs a percentage in the end but to do what the program requires, would I have to create an array?

    Here's the objective of the program:
    This problem is from a semi-recent programming competition.
    Lots of top programmers couldn't figure it out, but it only requires
    CS107 commands and info, and it's somewhat short (not too short, of course), so
    show how you would complete it!
     
     
     
    "COLLEGIATE PROGRAMMING COMPETITION, 2006"
    "Grade Dropping 101"
    Consider a college course [not cs107] in which students are allowed to drop
    scores for up to 3 course assignments.  But, students have to choose
    which ones to drop, to yield the highest course score.
    Each assignment may have a different maximum score.
    You must write a program that, given a list of assignment results,
    will calculate the best assignment percentage grade that can be obtained
    by dropping three of the assignments.
    [WARNING:
    You do NOT necessarily get it by dropping the lowest-percent assignments!]
     
     
    EXAMPLE:
    Consider these assignment scores:
    * 41 points out of 42
    * 22 pts out of 64
    * 2 pts out of 26
    * 11 pts out of 44
    * 24 pts out of 27
    * 26 pts out of 70
    * 4 pts out of 30
     
    The grade percentage when dropping zero assignments is:
    (41+22+2+11+24+26+4) / (42+64+26+44+27+70+30) = 42.9%
     
    But, you could improve that percentage, by choosing 3 scores to drop.
    What is the maximum percentage possible, by dropping 3 scores?
    (In this case, it is 56.8%)
     
     
     
    INPUT:
    Input to your program is:
    * The number of assignments.  (This is at least 4, and at most 30.)
    * The student's scores, and the maximum points, one at a time,
      for each of the assignments.
      (Scores are at least 0, and at most the maximum.)
      (The maximum scores at least 1, and at most 100.)
     
    OUTPUT:
    * The best possible final assignment percentage, from dropping 3 scores.

    Code I have so far:
    import java.io.*;
    public class HW8X
    {
    public static void main(String args[]) throws IOException
    {
        BufferedReader keybd = new BufferedReader(new InputStreamReader(System.in));
     
        System.out.print("Enter # of assignments: ");
        int x = Integer.parseInt(keybd.readLine());
     
        	double result = 0;
        	double result2 = 0;
     
        for (int i = 1; i <= x; i++)
        {    
        	System.out.print("Enter student's score: ");
        	double score = Double.parseDouble(keybd.readLine());
     
        	System.out.print("Enter max score: ");
        	double max = Double.parseDouble(keybd.readLine());
     
        	result = result + score;
        	result2 = result2 + max;
        }
        	System.out.println("Original percentage: " + (result/result2)*100.0 + "%");
     
    }// Ends main routine
     
    }// Ends class

    I know that I haven't added the conditions yet, but it's just a general outline for now. I'll be working on it more later.

    Thanks for the help!
    -Actinistia


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: "Grade Drop 101" - Should I use an array?

    Technically, no, you won't need an array. However, it will make life easier for you to use one.

  3. The Following User Says Thank You to helloworld922 For This Useful Post:

    Actinistia (May 5th, 2011)

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

    Default Re: "Grade Drop 101" - Should I use an array?

    Thanks!, I might try it without an array first then but if I can't figure that out, then I'll just go ahead and do the array.

Similar Threads

  1. Replies: 6
    Last Post: November 12th, 2010, 04:40 AM
  2. Java says:"Hello World". I say:"It works!"
    By Davidovic in forum Member Introductions
    Replies: 4
    Last Post: June 29th, 2010, 07:13 AM
  3. Replies: 1
    Last Post: March 15th, 2010, 10:03 PM
  4. [SOLVED] why does this code print 0.0 for the value and "F" as the letter grade?
    By etidd in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 12th, 2010, 10:38 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