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

Thread: HELP! Confused at why I'm not getting output

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    5
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question HELP! Confused at why I'm not getting output

    I'm fairly new to the java language but I can't seem to get my code to work. It is supposed to read an input file with names and 10 quiz scores for each person, then do a bubble sort until we have the top 8 scores, then create an average of those scores and give it a letter grade. The final output for each person is supposed to look like this:

    Name: blah - Grade: B

    The input file looks like this

    Bill Brasky
    81
    82
    98
    74
    76
    91
    88
    82
    92
    87
    next name
    and so on

    Here's what my code looks like:



    import java.io.*;
     
    public class StudentGrades
    {
    	public static void main(String args[]) throws Exception
    	{
    		String LETTER;
    		final int SIZE = 10;		// Number of quizzes
    		double score[] = new double[SIZE];   // Array used to store 10 quiz scores.
    		String stuName;			// Used to store name.
    		int x;
    		x = 0;
    		final int LIMIT = SIZE;
    		String stuScoreString;		// used to store what is read before changing to integer.
    		int stuScore = 0; 
    		int pairsToCompare;
    		double gradeAvg;
    		gradeAvg = 0;
    		boolean switchOccurred;
    		boolean done;
    		double temp;
    		double totalGrade;
    		totalGrade = 0;
    		int y;
    		y = 0;
    		System.out.println("Student Grade Report by Russ Penning");
     
    		// Start the input read.
    		FileReader fr = new FileReader("scores.dat");
    		BufferedReader br = new BufferedReader(fr);
     
    		// This is the work done in the fillArray() method
    		while((stuName = br.readLine()) != null)  // Use to read only the first line of the array before change to integer.
    		{
    			x = 0;
    			done = false;
    			while(x < LIMIT)   
    			{		
    			// Place value in array.
    			stuScoreString = br.readLine();
    			// Convert String to integer.
    			stuScore = Integer.parseInt(stuScoreString);		
    			score[x] = stuScore;
    			x++;    // Get ready for next input item.
     
    			}  // End of input loop.
    			stuScore = x - 2;
    			pairsToCompare = stuScore - 1;
     
    			// This is the work done in the sortArray() method
    			switchOccurred = true; // set flag to true
     
    			while(switchOccurred == true)
    			{
    			x = 0;
    			switchOccurred = false;
    				while(x < pairsToCompare)
    				{
    					if(score[x] > score[x + 1])
    					{
    					temp = score[x + 1];
    					score[x+1] = score[x];
    					score[x] = temp;
    					switchOccurred = true;
    				}
    				x++;	
    				}
    				pairsToCompare--;
    				}
    				while(x < stuScore)
    				{
    			        totalGrade = (score[x+2] + totalGrade);
    				x++;
    				}
    				gradeAvg = totalGrade / 8;
     
    				// Call calculateGrades method here		
    				LETTER = calculateGrades(gradeAvg);
    		}	
    		x = 0;
    		while(x < y)
    		{
    		LETTER = "";
    		System.out.println("Name: " + stuName + " -  Grade: " + LETTER);
    		x++;
    		}	
     
    		br.close();
    		System.exit(0);
     
    	} // End of main() method.
     
    	// Write calculateGrades method here.
    	public static String calculateGrades(double gradeAvg)
    	{
     
    		String LETTER;
     
    		if(gradeAvg >= 90)
    			LETTER = "A";
    		else if (gradeAvg >= 80)
    			LETTER = "B";
    		else if (gradeAvg >= 70)
    			LETTER = "C";
    		else if (gradeAvg >= 60)
    			LETTER = "D";
    		else
    			LETTER = "F";
     
    		return LETTER;
    	}
     
    } // End of StudentGrades class.

    Please let me know if anyone can think of anything. I am confused about it.


  2. #2
    Member
    Join Date
    Oct 2011
    Posts
    42
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default Re: HELP! Confused at why I'm not getting output

    Hi, what are you confusing about? Aren't you the owner of the code?

    java exception
    Last edited by hns1984; January 11th, 2012 at 06:56 PM.

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    5
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: HELP! Confused at why I'm not getting output

    Most of the code is taken from a previous program I worked on that worked perfectly fine. The only addition was calculating the average and creating a letter grade. There shouldn't be an issue with getting the correct output, but for some reason the only thing I'm getting on the report is the title.

  4. #4
    Junior Member
    Join Date
    Oct 2011
    Posts
    5
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: HELP! Confused at why I'm not getting output

    I have got it to give some sort of output, but now all it does it print the first name 1 time, second name 2 times and so on.

    Student Grade Report by Russ Penning

    Name: Billy Bob - Grade:
    Name: Ma Reynolds - Grade:
    Name: Ma Reynolds - Grade:
    Name: Pa Reynolds - Grade:
    Name: Pa Reynolds - Grade:
    Name: Pa Reynolds - Grade:
    Name: Sue Anne - Grade:
    Name: Sue Anne - Grade:
    Name: Sue Anne - Grade:
    Name: Sue Anne - Grade:
    Name: Uncle Mortimer - Grade:
    Name: Uncle Mortimer - Grade:
    Name: Uncle Mortimer - Grade:
    Name: Uncle Mortimer - Grade:
    Name: Uncle Mortimer - Grade:

    I'm still not getting anything back from the called method. Updated code:

    import java.io.*;
     
    public class StudentGrades
    {
    	public static void main(String args[]) throws Exception
    	{
    		String LETTER;
    		final int SIZE = 10;		// Number of quizzes
    		double score[] = new double[SIZE];   // Array used to store 10 quiz scores.
    		String stuName;			// Used to store name.
    		int x;
    		x = 0;
    		final int LIMIT = SIZE;
    		String stuScoreString;		// used to store what is read before changing to integer.
    		int stuScore = 0; 
    		int pairsToCompare;
    		boolean switchOccurred;
    		boolean done;
    		double temp;
    		double totalGrade;
    		totalGrade = 0;
    		int y;
    		y = 0;
    		System.out.println("Student Grade Report by Russ Penning");
    		System.out.println();
     
    		// Start the input read.
    		FileReader fr = new FileReader("scores.dat");
    		BufferedReader br = new BufferedReader(fr);
     
    		// This is the work done in the fillArray() method
    		while((stuName = br.readLine()) != null)  // Use to read only the first line of the array before change to integer.
    		{
    				y++;
    				x = 0;
    				done = false;
    				while(x < LIMIT)   
    				{		
    					// Place value in array.
    					stuScoreString = br.readLine();
    					// Convert String to integer.
    					stuScore = Integer.parseInt(stuScoreString);		
    					score[x] = stuScore;
    					x++;    // Get ready for next input item.
     
    				}  // End of input loop.
    				stuScore = x - 2;
    				pairsToCompare = stuScore - 1;
     
    				// This is the work done in the sortArray() method
    				switchOccurred = true; // set flag to true
     
    				while(switchOccurred == true)
    				{
    					x = 0;
    					switchOccurred = false;
    						while(x < pairsToCompare)
    						{
    							if(score[x] > score[x + 1])
    							{
    								temp = score[x + 1];
    								score[x+1] = score[x];
    								score[x] = temp;
    								switchOccurred = true;
    							}
    							x++;	
    						}
    						pairsToCompare--;
    					}
     
    				while(x < 8)
    				{
    					totalGrade = (score[x] + totalGrade);
    					x++;
    				}
     
    		// Call calculateGrades method here		
    		LETTER = calculateGrades(totalGrade);
     
    		x = 0;
    		while(x < y)
    		{
    			LETTER = "";
    			System.out.println("Name: " + stuName + " - Grade: " + LETTER);
    			x++;
    		}	
    		}
    		br.close();
    		System.exit(0);
     
    	} // End of main() method.
     
    	// Write calculateGrades method here.
    	public static String calculateGrades(double totalGrade)
    	{
     
    		String letterGrade;		
    		double gradeAvg;
    		gradeAvg = (totalGrade/8);
     
     
    		if(gradeAvg >= 90)
    			letterGrade = "A";
    		else if (gradeAvg >= 80)
    			letterGrade = "B";
    		else if (gradeAvg >= 70)
    			letterGrade = "C";
    		else if (gradeAvg >= 60)
    			letterGrade = "D";
    		else
    			letterGrade = "F";
     
    		return letterGrade;

Similar Threads

  1. help me , im confused!!!!
    By sephskie in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 11th, 2011, 10:52 AM
  2. Confused..
    By jadowers in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 5th, 2011, 12:56 PM
  3. [SOLVED] confused
    By joon in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 12th, 2011, 11:40 AM
  4. I'm confused...
    By acolar in forum Object Oriented Programming
    Replies: 1
    Last Post: April 14th, 2011, 12:14 PM
  5. Confusion with C/C++
    By Eric in forum Java Applets
    Replies: 0
    Last Post: December 22nd, 2008, 02:18 PM