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

Thread: Program due tomorrow. need some advice.

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Program due tomorrow. need some advice.

    Can someone please help me through this program. It is due tomorrow and i am so lost.
    Below is the Assignment itself.
    Write a program called FindGrade.java that will perform the following actions:

    1. Read lines from a text file in the instructor’s directory named Grades.dat (../instr/Grades.dat) that contains integer grade data for seven students. Each line contains the student number followed by 13 grades for that student. The first ten integers will be program grades; the next two will be test grades; and the thirteenth grade will be the final exam grade. For example, student number 100 might have a line that looked like this:
    100 0 20 30 40 55 59 65 80 90 100 95 100 88
    This would indicate that student number 100 didn’t submit the first program, made unsatisfactory grades (< 60) on the next five programs, and made grades ranging from 65 to 100 on the last four programs; the student made A’s on the two tests and an 88 on the final exam.

    2. Store each line’s data as a row in a 2-D array. Calculate and display the letter grade due each student based on the following rules:

    a. The average program grade counts 25%; the first test counts 20%; the second test counts 25%, and the final exam counts 30%.
    b. If a student doesn’t complete at least five programs with a grade of 60 or above, his numeric course grade must be lowered by ten points.
    c. A calculated course grade should be rounded up to the next integer if its fractional part is > = 0.5 (e.g., 89.5 rounds to 90.0, but 89.4 rounds to 89.0).
    d. A course grade of 90 or above is an A, 80 to 89 is a B, 70 to 79 is a C, 60 to 69 is a D, and below 60 is an F.
    e. CALCULATION MUST BE DONE IN A METHOD THAT IS CALLED IN YOUR PROGRAM. THE METHOD SHOULD RECEIVE THE GRADES FOR ONE STUDENT (i.e., one row of the table) AND RETURN THE LETTER GRADE FOR THAT STUDENT.

    3. Your program should be written so that changing one line of code will allow it to work for a different number of students.
    4. All displays should be done in the main, not in called methods. All of your output should be user-friendly, free of spelling errors, and easy to interpret.

    I am sooooo lost on how to do this. Any help would be great.


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Program due tomorrow. need some advice.

    Start earlier.
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Program due tomorrow. need some advice.

    i did start early im just confused on how to do it.

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Program due tomorrow. need some advice.

    What have you done? At the moment your post is "Here's my assignment, do it for me" which is not going to happen. You need to make an effort in writing the code yourself and asking specific questions.
    Improving the world one idiot at a time!

  5. #5
    Junior Member
    Join Date
    Sep 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Program due tomorrow. need some advice.

    let me copy it and post it. im not trying to make anyone do it for me.

  6. #6
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Program due tomorrow. need some advice.

    When posting code use code tags. Place [ code ] before and [ /code ] after without the spaces.
    Improving the world one idiot at a time!

  7. #7
    Junior Member
    Join Date
    Sep 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Program due tomorrow. need some advice.

    import java.io.*; 
    import java.util.*; 
    public class GradeCalculator {
     
      public static void main(String args[]) throws IOException
      {
        Scanner sf = new Scanner(new File("grades.dat"));
        int maxIndx = -1; 
        String text[] = new String[1000]; 
        while(sf.hasNext())
        {
          maxIndx++;
          text[maxIndx]=sf.nextLine();
        }
        sf.close();
        String answer="";
        int sum=0;
        double average=0;
        int n=0;
        String a="";
        for(int j=0;j<=maxIndx; j++)
        {
          Scanner sc=new Scanner(text[j]);
          sum=0;
          String s="";
          n=0;
          while(sc.hasNext())
          {
            int i=sc.nextInt();
            sum=sum+i;
            n=n+1;
          }
          average=sum/n;
          System.out.println(average);
        }
      }
    }

  8. #8
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Program due tomorrow. need some advice.

    Your question is?
    Improving the world one idiot at a time!

  9. #9
    Junior Member
    Join Date
    Sep 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Program due tomorrow. need some advice.

    i am having trouble with the calculating the average. it does calculate the average but it does not do it by the way my instructions say. i need it to take the first 10 and calculate the average for 25%, the next one for 20%, the next one for 25% and the last one as 30%. and then calculate the average.

  10. #10
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Program due tomorrow. need some advice.

    Look s like your code is calculating the average of all the values in the data. You need to calculate the average of the scores for the program assignments. Remember the first value is student id, the last is the exam and the third to last and second to last are test scores. Values 2 - 11 are the program assignments.
    Improving the world one idiot at a time!

  11. #11
    Junior Member
    Join Date
    Sep 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Program due tomorrow. need some advice.

    Thats why i need help. I cant figure out the code to do that for me. arrays for me in general are horrible and are confusing enough.

  12. #12
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Program due tomorrow. need some advice.

    If I wrote 14 numbers down on a piece of paper how would YOU add up the 2 - 11 values? Forget the code, just work out how to do it in your head or on paper.
    Improving the world one idiot at a time!

  13. #13
    Junior Member
    Join Date
    Sep 2013
    Posts
    18
    Thanks
    3
    Thanked 3 Times in 1 Post

    Default Re: Program due tomorrow. need some advice.

    It would really help to comment your code as well. It would not only help others to understand what you're trying to do with your code, it will help yourself to understand your objective.

    I see an int "n" that isn't really doing anything in your code, it's answer will always be the same. Also, you have assigned random strings that aren't doing anything at all. Also, the way you are calculating your average is incorrect, as has already been mentioned.

    Judging from the objective of the assignment, you have a pretty long way to go before you get this straightened out.

    You know what a 2D array is supposed to look like, right? You are only creating 1 dimensional arrays, so you will never achieve the objective with the way your array is defined.

    My advice would be to first figure out how to 2D arrays work, and figure out how to store each student id as a row, and the data for each student in a column. Once you have your array set up, it's just a matter of setting up a calculation for the average of 1 student, and then looping through each row until the end.

    In all honesty though, seeing what yo have produced so far, you would need more than a day to wrap your head around this. Good luck.

    --- Update ---

    oops, I do see n will increase on each pass of the while loop. Still does not come close to calculating a weighted average as the instructor is asking.

  14. #14
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Program due tomorrow. need some advice.

    Actually a 1D array is sufficient. All it needs to do is contain each line of data from the data file. One line per student = one element in the array. Then iterate over the array and process each student (line of data).
    Improving the world one idiot at a time!

  15. #15
    Junior Member
    Join Date
    Sep 2013
    Posts
    18
    Thanks
    3
    Thanked 3 Times in 1 Post

    Default Re: Program due tomorrow. need some advice.

    Right, but the instructions ask for a 2D array.
    "2. Store each line’s data as a row in a 2-D array. Calculate and display the letter grade due each student based on the following rules:"

  16. #16
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Program due tomorrow. need some advice.

    Arggh, I hate stoopid requirements.
    Improving the world one idiot at a time!

Similar Threads

  1. A poker program that gives advice based on pre set strategy...
    By mcbgun in forum Java Theory & Questions
    Replies: 0
    Last Post: December 19th, 2012, 10:19 AM
  2. Final Project Help Please? Due Tomorrow.
    By tylerreece22 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: April 23rd, 2012, 08:32 AM
  3. Help with Checkerboard GraphicsProgram (Due Tomorrow!)
    By strengthonor in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 16th, 2011, 09:40 AM
  4. Need switch statement for checker game (DUE TOMORROW!)
    By strengthonor in forum Loops & Control Statements
    Replies: 1
    Last Post: September 16th, 2011, 03:40 AM
  5. Need help on an Assignment but its due tomorrow!
    By Mob31 in forum Paid Java Projects
    Replies: 1
    Last Post: March 2nd, 2011, 06:54 AM

Tags for this Thread