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

Thread: Help!! Need to add a few things and I be lost!!

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help!! Need to add a few things and I be lost!!

    Her's my code with print out below.
    But I need the overall class average to be right, and I need to add A=x B=x C=x D=x F=x
    X= how many where given out

    I like to meet the person who said can't teach an old dog new tricks, I'm almost a believer.

    [CODE]  import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.util.Scanner;
     
     
     
    public class StudentGrades {
     
     
     
    //Declare variables and make the total test a constant equal to 3, since there are 3 tests
    private static double TOTAL_TESTS = 3;
     
     
        private static double average;
        private static char grade;
     
        //Use an array to store the 3 test scores
        private static int[] testScore = new int[3];
     
        private static String name;
        public StudentGrades() {
     
     
            //initialize the average, grade and name to zero,empty and null
            average = 0;
     
            grade = ' ';
     
            name="null";
        }
     
        public static void getAverage(Scanner inFile) {
        //create local variable to store temporary average in
        int tempAverage = 0;
        for (int num = 0; num <=2; num++) {
        testScore[num] = inFile.nextInt();
     
     
       //Add all the scores together per student
       tempAverage = testScore[num] + tempAverage;
     
     
     
     
     
       //Divide the average by the total amount of tests(3)
       average = (double)tempAverage / (TOTAL_TESTS);
     
            }
     
     
        }
     
        public char calculateGrade(Scanner inFile) {
     
            //Assign a grade to the appropriate numerical value 
     
     
            //A=90-100 B=80-89 C=70-79 D=60-69 F=Below 60
     
            if (average <= 100 && average >= 90) {
     
     
                grade = 'A';
            } else if (average < 90 && average >= 80) {
     
                grade = 'B';
     
     
            } else if (average < 80 && average >= 70) {
                grade = 'C';
     
     
            } else if (average < 70 && average >= 60) {
     
                grade = 'D';
     
     
            } else {
     
                grade = 'F';
     
     
            }
     
            //Return the appropriate grade 
            return grade;
     
        }
     
     
        public static void main(String[] args) throws FileNotFoundException {
     
    //Open the file that you are reading the information from
            try (Scanner inFile = new Scanner(new FileReader("TestDate.txt"))) {
                StudentGrades averages = new StudentGrades();
     
     
        //Read the input file until there is no text
                while (inFile.hasNext()) {
     
        // get the name of the student
     
                    name = inFile.next();
     
        // get the name of the student
     
                StudentGrades.getAverage(inFile);
     
        //Calculate the average
                    grade = averages.calculateGrade(inFile);
     
     
        //Output each students name, test scores, average numerical grade and letter grade
     
     
                    for (int num = 0; num <= 2; num++) {
                    //calculate sum of all array elements 
     
                    }
     
     
     
    System.out.printf("%s\t has an average grade of  %.2f  You will receive a %s in this class.\n", name, average, grade);
    }
     
     
    System.out.printf("\nOverall Class Average is %.2f\n",average/1.4);         
     
    //generates three random numbers between 0 and 50, calculates the average.
          int one,two,three;
          one=(int)(Math.random()*(51));
          two=(int)(Math.random()*(51));
          three=(int)(Math.random()*(51));
     
          int average=(one+two+three)/3;
          System.out.printf("\nThe following program generates 3 random numbers, then averages them.\n");
          System.out.printf("\nThe average of\t"+one+"  "+two+"  "+three+"  is   "+average);
     
     
     
            }
     
        }
     
     
    }
    [/CODE]

    Current print out is:

    Connie has an average grade of 85.33 You will receive a B in this class.
    James has an average grade of 92.00 You will receive a A in this class.
    Susan has an average grade of 52.33 You will receive a F in this class.
    Jake has an average grade of 66.33 You will receive a D in this class.
    Karen has an average grade of 77.33 You will receive a C in this class.
    Bill has an average grade of 99.00 You will receive a A in this class.
    Fred has an average grade of 85.33 You will receive a B in this class.
    Cheryl has an average grade of 75.00 You will receive a C in this class.
    Pam has an average grade of 65.00 You will receive a D in this class.
    Steve has an average grade of 45.00 You will receive a F in this class.
    John has an average grade of 86.33 You will receive a B in this class.
    David has an average grade of 81.67 You will receive a B in this class.
    Corina has an average grade of 91.67 You will receive a A in this class.
    Delia has an average grade of 74.00 You will receive a C in this class.
    Evan has an average grade of 99.00 You will receive a A in this class.

    Overall Class Average is 70.71

    The following program generates 3 random numbers, then averages them.

    The average of 45 35 23 is 34
    ----jGRASP: operation complete.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help!! Need to add a few things and I be lost!!

    I need the overall class average to be right,
    Please explain what the problem is. Show the current output and explain what is wrong with it and show the correct answer.

    I need to add A=x B=x C=x D=x F=x X= how many where given out
    Can you explain what you are asking here? An example perhaps?

Similar Threads

  1. [SOLVED] Things Won't Move
    By zeraxis in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 2nd, 2011, 08:46 AM
  2. A better way to do things?
    By SnarkKnuckle in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 18th, 2011, 12:52 PM
  3. Displaying things in gui
    By KrisTheSavage in forum AWT / Java Swing
    Replies: 2
    Last Post: March 29th, 2010, 12:21 PM
  4. XML, and other things.
    By Tortex in forum The Cafe
    Replies: 0
    Last Post: March 27th, 2010, 03:33 PM
  5. How would i do these things??
    By Curious in forum Java Theory & Questions
    Replies: 4
    Last Post: February 21st, 2010, 08:33 PM