Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2012
    Posts
    19
    Rep Power
    0

    Default Having trouble with simple grade averages/raised averages program

    Somewhere along the line, the if/else statements nested inside the while loop are organized wrong.
    This program should use a scanner to take the following inputs: the number of students that grades are entered for, the number of grades entered for each student, and the grades for each student. At the end, the program calculates the average grade for each student, and the raised average grade for each student (by dropping the lowest grade).

    Here is the program below:
    Last edited by LogicalOutlier; 01-19-2012 at 08:39 PM.

  2. #2
    Join Date
    Jan 2012
    Posts
    19
    Rep Power
    0

    Default Re: Having trouble with simple grade averages/raised averages program

    import java.util.Scanner;

    public class Averages {

    public static void main(String[] args) {

    //variable declarations
    int allStart = 0;
    int allTotal = 0;
    int start;
    int studTotal = 0;
    int studRaiseTotal = 0;
    int numScores = 0;
    int lowest = 0;
    int score = 0;

    Scanner testScan = new Scanner(System.in);
    System.out.println("How many students are you entering scores for?"); //number of students
    int students = testScan.nextInt();
    System.out.println("How many scores do you need to enter for each student?");
    numScores = testScan.nextInt();

    //average for each student
    double studRaiseAve;
    double studNormAve;

    //average for all students
    double allAve;
    double allRaiseAve;

    while(allStart<students){

    for(start = 0; start<numScores; start++)
    {
    System.out.println("Enter a score.");
    lowest = testScan.nextInt();
    score = lowest;
    studTotal+=score;

    if(start==-1){
    testScan.close();
    }

    if(score<lowest);
    {
    studRaiseTotal = studTotal-lowest;
    studRaiseAve = (double)(studRaiseTotal/(numScores-1));
    System.out.println("Here is the student's scaled score.");
    System.out.println(studRaiseAve);
    }

    studNormAve = (double)(studTotal/numScores);
    System.out.println("Here is the student's average test scores.");
    System.out.println(studNormAve);

    if (studNormAve>=70){
    System.out.println("This student passes.");
    }

    else{
    System.out.println("This student fails.");
    }

    System.out.println("Here is the student's total test scores.");
    System.out.println(studTotal);

    }
    start++;

    allAve = (double)(allTotal/students);
    System.out.println("Here is the class's average.");
    System.out.println(allAve);

    allTotal = studRaiseTotal;
    allRaiseAve = (double)(allTotal/(students));
    System.out.println("Here is the raised class average.");
    System.out.println(allRaiseAve);

    }

    }
    }

  3. #3
    Join Date
    Jan 2012
    Posts
    19
    Rep Power
    0

    Default Re: Having trouble with simple grade averages/raised averages program

    And here is what it returns:

    How many students are you entering scores for?
    2
    How many scores do you need to enter for each student?
    2
    Enter a score.
    90
    Here is the student's scaled score.
    0.0
    Here is the student's average test scores.
    45.0
    This student fails.
    Here is the student's total test scores.
    90

    ...and it keeps returning that

  4. #4
    diamonddragon is offline Senior Member
    Join Date
    Jan 2012
    Posts
    210
    Rep Power
    3

    Default Re: Having trouble with simple grade averages/raised averages program

    First: delete while loop, cause it keeps returning "that".
    Second: delete something like:

    if(start==-1){
    testScan.close();
    }

    from for loop, cause for loop have its own condition evaluation like bold one: for(start = 0; start<numScores; start++)

  5. #5
    Join Date
    Jan 2012
    Posts
    19
    Rep Power
    0

    Default Re: Having trouble with simple grade averages/raised averages program

    How many students are you entering scores for?
    2
    How many scores do you need to enter for each student?
    3
    Enter a score.
    90
    Here is the student's scaled score.
    0.0
    Here is the student's average test scores.
    30.0
    This student fails.
    Here is the student's total test scores.
    90
    Enter a score.
    80
    Here is the student's scaled score.
    45.0
    Here is the student's average test scores.
    56.0
    This student fails.
    Here is the student's total test scores.
    170
    Enter a score.
    60
    Here is the student's scaled score.
    85.0
    Here is the student's average test scores.
    76.0
    This student passes.
    Here is the student's total test scores.
    230
    Here is the class's average.
    0.0
    Here is the raised class average.
    85.0

    Is what it's returning now. I'm going to keep tweaking this. Thanks!
    Last edited by LogicalOutlier; 01-20-2012 at 12:04 AM.

  6. #6
    diamonddragon is offline Senior Member
    Join Date
    Jan 2012
    Posts
    210
    Rep Power
    3

    Default Re: Having trouble with simple grade averages/raised averages program

    Use "\n" in print() or println() method in order to get an extra empty line between block of the text.
    Delete start++ in the bottom of foor loop body {...}, because it is already incremented in for loop each time after loop iteration, and before testing condition.

  7. #7
    Join Date
    Jan 2012
    Posts
    19
    Rep Power
    0

    Default Re: Having trouble with simple grade averages/raised averages program

    New version:

    import java.util.Scanner;

    public class Averages {


    public static void main(String[] args) {
    int allTotal = 0;
    int start = 0;
    int studTotal = 0;
    int studRaiseTotal = 0;
    int numScores = 0;
    int lowest = 0;
    int score = 0;
    double studRaiseAve = 0;
    double studNormAve = 0;
    double allAve = 0;
    double allRaiseAve = 0;
    int i;

    Scanner testScan = new Scanner(System.in);
    System.out.println("How many students are you entering scores for?"); //number of students
    int students = testScan.nextInt();
    System.out.println("How many scores do you need to enter for each student?");
    numScores = testScan.nextInt();


    for(start = 0; start<numScores; start++)
    {
    for(i = 0; i < students; i++){
    int n = i+1;
    System.out.println("Enter a score for student number "+n);
    lowest = testScan.nextInt();
    score = lowest;
    studTotal+=score;

    if((score<lowest)&&numScores>1);
    {
    studRaiseTotal = studTotal-lowest;
    studRaiseAve = (double)(studRaiseTotal/(numScores-1));
    }

    if((score<lowest)&&numScores==1){
    studRaiseTotal = studTotal;
    studRaiseAve = (double) (studRaiseTotal/numScores);
    }
    }
    System.out.println("Here is the student's scaled score.");
    System.out.println(studRaiseAve);
    studNormAve = (double)(studTotal/numScores);
    System.out.println("Here is the student's average test scores.");
    System.out.println(studNormAve);

    if (studNormAve>=70){
    System.out.println("This student passes.");
    }

    else{
    System.out.println("This student fails.");
    }

    System.out.println("Here is the student's total test scores.");
    System.out.println(studTotal);

    }

    allAve = (double)(allTotal/students);
    System.out.println("Here is the class's average.");
    System.out.println(allAve);

    allTotal = studRaiseTotal;
    allRaiseAve = (double)(allTotal/(students));
    System.out.println("Here is the raised class average.");
    System.out.println(allRaiseAve);

    }
    }

  8. #8
    Join Date
    Jan 2012
    Posts
    19
    Rep Power
    0

    Default Re: Having trouble with simple grade averages/raised averages program

    And what it returns:

    How many students are you entering scores for?
    2
    How many scores do you need to enter for each student?
    2
    Enter a score for student number 1
    90
    Enter a score for student number 2
    96
    Here is the student's scaled score.
    90.0
    Here is the student's average test scores.
    93.0
    This student passes.
    Here is the student's total test scores.
    186
    Enter a score for student number 1
    2
    Enter a score for student number 2
    2
    Here is the student's scaled score.
    188.0
    Here is the student's average test scores.
    95.0
    This student passes.
    Here is the student's total test scores.
    190
    Here is the class's average.
    0.0
    Here is the raised class average.
    94.0

Similar Threads

  1. Looping over averages in an int[][] array
    By adventurerOK in forum Advanced Java
    Replies: 1
    Last Post: 09-28-2011, 09:16 PM
  2. Beginner Loops for averages
    By mobosecomin in forum New To Java
    Replies: 6
    Last Post: 10-17-2010, 09:17 PM
  3. Problem with Sums and Averages in Sales Report
    By DavidEvans in forum New To Java
    Replies: 9
    Last Post: 04-21-2010, 08:57 PM
  4. Averages of user inputed values (Need Help)
    By Zebra in forum New To Java
    Replies: 2
    Last Post: 04-16-2008, 01:51 PM
  5. Replies: 4
    Last Post: 04-16-2008, 01:26 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •