Results 1 to 11 of 11
  1. #1
    BariMutation is offline Member
    Join Date
    Oct 2010
    Posts
    22
    Rep Power
    0

    Default Looping WAY too many times...

    I've been pulling my hair out with this program! Essentially, it is supposed to ask how many students the user wants, and then randomly generate scores for the assignments and tests section, output all of these scores, and finally output a letter grade. Instead, it's looping each section WAY too many times, and I can't for the life of me figure it out. Can anyone please help? I posted what I believe to be the problem, but if nothing is wrong, I'll post each method. Thank you so much for any help!!!!!


    Essentially, this is the method that I believe to be causing the problem because it's the only one that's looping more than it should for each student.

    Java Code:
    		public int ComputeTestScore()
    			{
    				int finalPAT = 0;
    				for (int n=1; n<=1; n++)
    					{
    						Random gradeGenerator = new Random();
    						int grade = gradeGenerator.nextInt(31);
    						System.out.println("PAT: " + grade);
    						finalPAT += grade;
    					}		//End of PAT Section
    				
    				int finalLOs = 0;
    				for (int m=1; m<=15; m++)
    					{
    						Random gradeGenerator = new Random();
    						int grade = gradeGenerator.nextInt(31);
    						System.out.println("LO "+ m + ": " + grade);
    						finalLOs += grade;
    					}		//End of LOs Section
    				
    				int finalMidterms = 0;
    				Random gradeGenerator = new Random();
    				for (int o=1; o<=2; o++)
    					{
    						int grade = gradeGenerator.nextInt(61);
    						System.out.println("Midterm "+ o + ": " + grade);
    						finalMidterms += grade;
    					}		//End of Midterms Section
    		
    				int finalfE = 0;
    				for (int p=1; p<=1; p++)
    					{
    						int grade = gradeGenerator.nextInt(121);
    						System.out.println("Final Exam: " + grade);
    						finalfE += grade;
    					}
    	
    				int OverallTests = 0;
    				OverallTests = finalfE + finalMidterms + finalPAT + finalLOs;//End of FinalExam Section
    				return OverallTests;
    			}
    Last edited by BariMutation; 10-14-2010 at 11:47 PM.

  2. #2
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default

    BariMutation,

    I can't see any problem with the code you posted.
    Is each method being called numerous times before moving on to the next or is the code doing what is required just more times than expected?

    If it is the first case, there is a problem with the called method. If the second case applies, there is a problem with the main method.

    Please post the code for the relevant scenario.

    Regards.

  3. #3
    BariMutation is offline Member
    Join Date
    Oct 2010
    Posts
    22
    Rep Power
    0

    Default

    Well, it depends - the user could input, say, 3 students. Then the assignment, tests, and letter grade methods out be called (respectively) once for the 1st student. Then again for the 2nd student, and so on. Here is the entire code, and thanks for helping!

    Java Code:
    import java.util.*;
    import java.util.Random;
    
    public class CourseGradeCalculator
    	{	
    		public static void main (String [] args)
    			{
    				Scanner scanner = new Scanner(System.in);
    				System.out.println("Please enter the number of students.");
    				int studentNumber = 0;
    					studentNumber=scanner.nextInt();
    					
    				for (int i=1; i<=studentNumber; i++)
    					{
    						System.out.println("Student " + i + ": ");
    						CourseGradeCalculator newInstance = new CourseGradeCalculator();
    							newInstance.ComputeAssignmentScore();
    							newInstance.ComputeTestScore();
    							newInstance.ComputeLetterGrade();
    					}
    			}	
    		public int ComputeAssignmentScore()
    			{
    				Scanner scanner = new Scanner(System.in);
    			
    				int finalAssignments = 0;
    				for (int j=1; j<=6; j++)
    					{
    						Random gradeGenerator = new Random();
    						int grade = gradeGenerator.nextInt(101);
    						System.out.println("Assignment " + j + ": " + grade);
    						finalAssignments += grade;
    					}		//End of Assignments Section
    				
    				int finalAttendance = 0;
    				for (int k=1; k<=1; k++)
    					{
    						Random gradeGenerator = new Random();
    						int grade = gradeGenerator.nextInt(26);
    						System.out.println("Attendance: " + grade);
    						finalAttendance += grade;
    					}	//End of Attendance Section
    				
    				int finalLabs = 0;
    				for (int l=1; l<=15; l++)
    					{
    						Random gradeGenerator = new Random();
    						int grade = gradeGenerator.nextInt(36);
    						System.out.println("Lab " + l + ": " + grade);
    						finalLabs += grade;
    					}	//End of Labs Section
    					
    				int finalQuizzes = 0;
    				for (int q=1; q<=1; q++)
    					{
    						Random gradeGenerator = new Random();
    						int grade = gradeGenerator.nextInt(51);
    						System.out.println("Quizzes: " + grade);
    					}
    				
    				int OverallAssignments = 0;
    				OverallAssignments = finalLabs + finalAttendance + finalAssignments;//Finalizes the overall assignment section
    					
    				return OverallAssignments;	
    			}
    			
    		public int ComputeTestScore()
    			{
    				int finalPAT = 0;
    				for (int n=1; n<=1; n++)
    					{
    						Random gradeGenerator = new Random();
    						int grade = gradeGenerator.nextInt(31);
    						System.out.println("PAT: " + grade);
    						finalPAT += grade;
    					}		//End of PAT Section
    				
    				int finalLOs = 0;
    				for (int m=1; m<=15; m++)
    					{
    						Random gradeGenerator = new Random();
    						int grade = gradeGenerator.nextInt(31);
    						System.out.println("LO "+ m + ": " + grade);
    						finalLOs += grade;
    					}		//End of LOs Section
    				
    				int finalMidterms = 0;
    				Random gradeGenerator = new Random();
    				for (int o=1; o<=2; o++)
    					{
    						int grade = gradeGenerator.nextInt(61);
    						System.out.println("Midterm "+ o + ": " + grade);
    						finalMidterms += grade;
    					}		//End of Midterms Section
    		
    				int finalfE = 0;
    				for (int p=1; p<=1; p++)
    					{
    						int grade = gradeGenerator.nextInt(121);
    						System.out.println("Final Exam: " + grade);
    						finalfE += grade;
    					}
    	
    				int OverallTests = 0;
    				OverallTests = finalfE + finalMidterms + finalPAT + finalLOs;//End of FinalExam Section
    				return OverallTests;
    			}
    			
    		public void ComputeLetterGrade()
    			{
    				if (ComputeTestScore() <= 149)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (ComputeTestScore() <= 164 && ComputeTestScore() >= 150 && ComputeAssignmentScore() <= 779)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (ComputeTestScore() <= 164 && ComputeTestScore() >= 150 && ComputeAssignmentScore() <=1079 && ComputeAssignmentScore() >= 780)
    					{
    						System.out.println("The final grade for the student is a D.");
    					}
    				else if (ComputeTestScore() <= 164 && ComputeTestScore() >= 150 && ComputeAssignmentScore() <= 1200 && ComputeAssignmentScore() >= 1080)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (ComputeTestScore() <= 179 && ComputeTestScore() >= 165 && ComputeAssignmentScore() <= 719)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (ComputeTestScore() <= 179 && ComputeTestScore() >= 165 && ComputeAssignmentScore() <= 959 && ComputeAssignmentScore() >= 720)
    					{
    						System.out.println("The final grade for the student is a D.");
    					}
    				else if (ComputeTestScore() <= 179 && ComputeTestScore() >= 165 && ComputeAssignmentScore() >= 960 && ComputeAssignmentScore() <= 1200)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (ComputeTestScore() <= 194 && ComputeTestScore() >= 180 && ComputeAssignmentScore() <= 659)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (ComputeTestScore() <= 194 && ComputeTestScore() >= 180 && ComputeAssignmentScore() <=899 && ComputeAssignmentScore() >= 660)
    					{
    						System.out.println("The final grade for the student is a D.");
    					}
    				else if (ComputeTestScore() <= 194 && ComputeTestScore() >= 180 && ComputeAssignmentScore() <= 1139 && ComputeAssignmentScore() >= 900)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (ComputeTestScore() <= 194 && ComputeTestScore() >= 180 && ComputeAssignmentScore() <= 1200 && ComputeAssignmentScore() >= 1140)
    					{
    						System.out.println("The final grade for the student is a B.");
    					}
    				else if (ComputeTestScore() <= 209 && ComputeTestScore() >= 195 && ComputeAssignmentScore() <= 659)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (ComputeTestScore() <= 209 && ComputeTestScore() >= 195 && ComputeAssignmentScore() >= 660 && ComputeAssignmentScore() <= 839)
    					{
    						System.out.println("The final grade for the student is a D.");
    					}
    				else if (ComputeTestScore() <= 209 && ComputeTestScore() >= 195 && ComputeAssignmentScore() >= 840 && ComputeAssignmentScore() <= 1079)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (ComputeTestScore() <= 209 && ComputeTestScore() >= 195 && ComputeAssignmentScore() >= 1080 && ComputeAssignmentScore() <= 1200)
    					{
    						System.out.println("The final grade for the student is a B.");
    					}
    				else if (ComputeTestScore() <= 224 && ComputeTestScore() >= 210 && ComputeAssignmentScore() <= 599)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (ComputeTestScore() <= 224 && ComputeTestScore() >= 210 && ComputeAssignmentScore() >= 600 && ComputeAssignmentScore() <= 779)
    					{
    						System.out.println("The final grade for the student is a D.");
    					}
    				else if (ComputeTestScore() <= 224 && ComputeTestScore() >= 210 && ComputeAssignmentScore() >= 780 && ComputeAssignmentScore() <= 959)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (ComputeTestScore() <= 224 && ComputeTestScore() >= 210 && ComputeAssignmentScore() >= 900 && ComputeAssignmentScore() <= 1200)
    					{
    						System.out.println("The final grade for the student is a B.");
    					}
    				else if (ComputeTestScore() <= 239 && ComputeTestScore() >= 225 && ComputeAssignmentScore() <= 599)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (ComputeTestScore() <= 239 && ComputeTestScore() >= 225 && ComputeAssignmentScore() >= 600 && ComputeAssignmentScore() <= 719)
    					{
    						System.out.println("The final grade for the student is a D.");
    					}
    				else if (ComputeTestScore() <= 239 && ComputeTestScore() >= 225 && ComputeAssignmentScore() >= 720 && ComputeAssignmentScore() <= 899)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (ComputeTestScore() <= 239 && ComputeTestScore() >= 225 && ComputeAssignmentScore() >= 900 && ComputeAssignmentScore() <= 1139)
    					{
    						System.out.println("The final grade for the student is a B.");
    					}
    				else if (ComputeTestScore() <= 239 && ComputeTestScore() >= 225 && ComputeAssignmentScore() >= 1140 && ComputeAssignmentScore() <= 1200)
    					{
    						System.out.println("The final grade for the student is an A.");
    					}
    				else if (ComputeTestScore() >= 240 && ComputeTestScore() <= 254 && ComputeAssignmentScore() <= 599)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (ComputeTestScore() >= 240 && ComputeTestScore() <= 254 && ComputeAssignmentScore() >= 600 && ComputeAssignmentScore() <= 659)
    					{
    						System.out.println("The final grade for the student is a D.");
    					}
    				else if (ComputeTestScore() >= 240 && ComputeTestScore() <= 254 && ComputeAssignmentScore() >= 660 && ComputeAssignmentScore() <= 839)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (ComputeTestScore() >= 240 && ComputeTestScore() <= 254 && ComputeAssignmentScore() >= 840 && ComputeAssignmentScore() <= 1079)
    					{
    						System.out.println("The final grade for the student is a B.");
    					}
    				else if (ComputeTestScore() >= 240 && ComputeTestScore() <= 254 && ComputeAssignmentScore() >= 1080 && ComputeAssignmentScore() <= 1200)
    					{
    						System.out.println("The final grade for the student is an A.");
    					}
    				else if (ComputeTestScore() >= 255 && ComputeTestScore() <= 269 && ComputeAssignmentScore() <= 599)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (ComputeTestScore() >= 255 && ComputeTestScore() <= 269 && ComputeAssignmentScore() >= 600 && ComputeAssignmentScore() <= 779)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (ComputeTestScore() >= 255 && ComputeTestScore() <= 269 && ComputeAssignmentScore() >= 780 && ComputeAssignmentScore() <= 1019)
    					{
    						System.out.println("The final grade for the student is a B.");
    					}
    				else if (ComputeTestScore() >= 255 && ComputeTestScore() <= 269 && ComputeAssignmentScore() >= 1020 && ComputeAssignmentScore() <= 1200)
    					{
    						System.out.println("The final grade for the student is an A.");
    					}
    				else if (ComputeTestScore() >= 270 && ComputeTestScore() <= 284 && ComputeAssignmentScore() <= 599)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (ComputeTestScore() >= 270 && ComputeTestScore() <= 284 && ComputeAssignmentScore() >= 600 && ComputeAssignmentScore() <= 779)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (ComputeTestScore() >= 270 && ComputeTestScore() <= 284 && ComputeAssignmentScore() >= 780 && ComputeAssignmentScore() <= 899)
    					{
    						System.out.println("The final grade for the student is a B.");
    					}
    				else if (ComputeTestScore() >= 270 && ComputeTestScore() <= 284 && ComputeAssignmentScore() >= 900 && ComputeAssignmentScore() <= 1200)
    					{
    						System.out.println("The final grade for the student is an A.");
    					}
    				else if (ComputeTestScore() >= 285 && ComputeTestScore() <= 300 && ComputeAssignmentScore() <= 599)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (ComputeTestScore() >= 285 && ComputeTestScore() <= 300 && ComputeAssignmentScore() >= 600 && ComputeAssignmentScore() <= 719)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (ComputeTestScore() >= 285 && ComputeTestScore() <= 300 && ComputeAssignmentScore() >= 720 && ComputeAssignmentScore() <= 899)
    					{
    						System.out.println("The final grade for the student is a B.");
    					}
    				else if (ComputeTestScore() >= 285 && ComputeTestScore() <= 300 && ComputeAssignmentScore() >= 900 && ComputeAssignmentScore() <= 1200)
    					{
    						System.out.println("The final grade for the student is an A.");
    					}
    				System.out.println("                 ");
    			}
    	}

  4. #4
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    786
    Rep Power
    5

    Default

    in each of your if-else statements you call the method ComputeTestScore several times :)

    Java Code:
    if (ComputeTestScore() <= 149) {
    			System.out.println("The final grade for the student is an F.");
    		} else if (ComputeTestScore() <= 164 && ComputeTestScore() >= 150
    				&& ComputeAssignmentScore() <= 779) {
    maybe you should write int testscore = newInstance.ComputeTestScore(); in your main method an pass the "testscore" to the ComputeLetterGrade method!

  5. #5
    BariMutation is offline Member
    Join Date
    Oct 2010
    Posts
    22
    Rep Power
    0

    Default

    Okay, I completely understand what you're saying, but now something else is happening. I did this to all of the "ComputeTestScore()" in the ComputeLetterGrade method:

    Java Code:
    if (testscore <= 149)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    And did this to the main method:

    Java Code:
    		public static void main (String [] args)
    			{
    				Scanner scanner = new Scanner(System.in);
    				System.out.println("Please enter the number of students.");
    				int studentNumber = 0;
    					studentNumber=scanner.nextInt();
    					
    				for (int i=1; i<=studentNumber; i++)
    					{
    						System.out.println("Student " + i + ": ");
    						CourseGradeCalculator newInstance = new CourseGradeCalculator();
    							newInstance.ComputeAssignmentScore();
    							int testscore = newInstance.ComputeTestScore();
    							newInstance.ComputeLetterGrade();
    					}
    			}
    But also, if what you're saying is true, then wouldn't I also have trouble with the ComputeAssignmentScore method, since that's also being called in the ComputeLetterGrade method?

  6. #6
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    786
    Rep Power
    5

    Default

    ok, you must inject the testscore to the method....

    newInstance.ComputeLetterGrade(testscore);

    and

    public void ComputeLetterGrade(int testscore)


    or you call the method ComputeTestScore() in ComputeLetterGrade and not in your main method, or .... or..... :)

    EDIT:
    Quote Originally Posted by BariMutation View Post
    I also have trouble with the ComputeAssignmentScore method, since that's also being called in the ComputeLetterGrade method?
    ahhhh yes, its the same....
    Last edited by eRaaaa; 10-15-2010 at 12:40 AM.

  7. #7
    BariMutation is offline Member
    Join Date
    Oct 2010
    Posts
    22
    Rep Power
    0

    Default

    Quote Originally Posted by eRaaaa View Post
    ahhhh yes, its the same....
    Sorry, I don't understand that part... are you saying that now you don't get it, or that you're still right? lol

  8. #8
    BariMutation is offline Member
    Join Date
    Oct 2010
    Posts
    22
    Rep Power
    0

    Default

    SCRATCH THAT! I freaking love you dude, you got it working! But, one tiny problem - now it won't output the letter grade from the ComputeLetterGrade method. At the very end, it should say "The final grade for the student is an F." (or whatever they earned) Here's the entire program again...

    Java Code:
    import java.util.*;
    import java.util.Random;
    
    public class CourseGradeCalculator
    	{	
    		public static void main (String [] args)
    			{
    				Scanner scanner = new Scanner(System.in);
    				System.out.println("Please enter the number of students.");
    				int studentNumber = 0;
    					studentNumber=scanner.nextInt();
    					
    				for (int i=1; i<=studentNumber; i++)
    					{
    						System.out.println("Student " + i + ": ");
    						CourseGradeCalculator newInstance = new CourseGradeCalculator();
    							newInstance.ComputeAssignmentScore();
    							int testscore = newInstance.ComputeTestScore();
    							newInstance.ComputeLetterGrade(testscore);
    					}
    			}	
    		public int ComputeAssignmentScore()
    			{
    				Scanner scanner = new Scanner(System.in);
    			
    				int finalAssignments = 0;
    				for (int j=1; j<=6; j++)
    					{
    						Random gradeGenerator = new Random();
    						int grade = gradeGenerator.nextInt(101);
    						System.out.println("Assignment " + j + ": " + grade);
    						finalAssignments += grade;
    					}		//End of Assignments Section
    				
    				int finalAttendance = 0;
    				for (int k=1; k<=1; k++)
    					{
    						Random gradeGenerator = new Random();
    						int grade = gradeGenerator.nextInt(26);
    						System.out.println("Attendance: " + grade);
    						finalAttendance += grade;
    					}	//End of Attendance Section
    				
    				int finalLabs = 0;
    				for (int l=1; l<=15; l++)
    					{
    						Random gradeGenerator = new Random();
    						int grade = gradeGenerator.nextInt(36);
    						System.out.println("Lab " + l + ": " + grade);
    						finalLabs += grade;
    					}	//End of Labs Section
    					
    				int finalQuizzes = 0;
    				for (int q=1; q<=1; q++)
    					{
    						Random gradeGenerator = new Random();
    						int grade = gradeGenerator.nextInt(51);
    						System.out.println("Quizzes: " + grade);
    					}
    				
    				int OverallAssignments = 0;
    				OverallAssignments = finalLabs + finalAttendance + finalAssignments;//Finalizes the overall assignment section
    					
    				return OverallAssignments;	
    			}
    			
    		public int ComputeTestScore()
    			{
    				int finalPAT = 0;
    				for (int n=1; n<=1; n++)
    					{
    						Random gradeGenerator = new Random();
    						int grade = gradeGenerator.nextInt(31);
    						System.out.println("PAT: " + grade);
    						finalPAT += grade;
    					}		//End of PAT Section
    				
    				int finalLOs = 0;
    				for (int m=1; m<=15; m++)
    					{
    						Random gradeGenerator = new Random();
    						int grade = gradeGenerator.nextInt(31);
    						System.out.println("LO "+ m + ": " + grade);
    						finalLOs += grade;
    					}		//End of LOs Section
    				
    				int finalMidterms = 0;
    				Random gradeGenerator = new Random();
    				for (int o=1; o<=2; o++)
    					{
    						int grade = gradeGenerator.nextInt(61);
    						System.out.println("Midterm "+ o + ": " + grade);
    						finalMidterms += grade;
    					}		//End of Midterms Section
    		
    				int finalfE = 0;
    				for (int p=1; p<=1; p++)
    					{
    						int grade = gradeGenerator.nextInt(121);
    						System.out.println("Final Exam: " + grade);
    						finalfE += grade;
    					}
    	
    				int OverallTests = 0;
    				OverallTests = finalfE + finalMidterms + finalPAT + finalLOs;//End of FinalExam Section
    				return OverallTests;
    			}
    			
    		public void ComputeLetterGrade(int testscore)
    			{
    				if (testscore <= 149)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (testscore <= 164 && testscore >= 150 && ComputeAssignmentScore() <= 779)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (testscore <= 164 && testscore >= 150 && ComputeAssignmentScore() <=1079 && ComputeAssignmentScore() >= 780)
    					{
    						System.out.println("The final grade for the student is a D.");
    					}
    				else if (testscore <= 164 && testscore >= 150 && ComputeAssignmentScore() <= 1200 && ComputeAssignmentScore() >= 1080)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (testscore <= 179 && testscore >= 165 && ComputeAssignmentScore() <= 719)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (testscore <= 179 && testscore >= 165 && ComputeAssignmentScore() <= 959 && ComputeAssignmentScore() >= 720)
    					{
    						System.out.println("The final grade for the student is a D.");
    					}
    				else if (testscore <= 179 && testscore >= 165 && ComputeAssignmentScore() >= 960 && ComputeAssignmentScore() <= 1200)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (testscore <= 194 && testscore >= 180 && ComputeAssignmentScore() <= 659)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (testscore <= 194 && testscore >= 180 && ComputeAssignmentScore() <=899 && ComputeAssignmentScore() >= 660)
    					{
    						System.out.println("The final grade for the student is a D.");
    					}
    				else if (testscore <= 194 && testscore >= 180 && ComputeAssignmentScore() <= 1139 && ComputeAssignmentScore() >= 900)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (testscore <= 194 && testscore >= 180 && ComputeAssignmentScore() <= 1200 && ComputeAssignmentScore() >= 1140)
    					{
    						System.out.println("The final grade for the student is a B.");
    					}
    				else if (testscore <= 209 && testscore >= 195 && ComputeAssignmentScore() <= 659)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (testscore <= 209 && testscore >= 195 && ComputeAssignmentScore() >= 660 && ComputeAssignmentScore() <= 839)
    					{
    						System.out.println("The final grade for the student is a D.");
    					}
    				else if (testscore <= 209 && testscore >= 195 && ComputeAssignmentScore() >= 840 && ComputeAssignmentScore() <= 1079)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (testscore <= 209 && testscore >= 195 && ComputeAssignmentScore() >= 1080 && ComputeAssignmentScore() <= 1200)
    					{
    						System.out.println("The final grade for the student is a B.");
    					}
    				else if (testscore <= 224 && testscore >= 210 && ComputeAssignmentScore() <= 599)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (testscore <= 224 && testscore >= 210 && ComputeAssignmentScore() >= 600 && ComputeAssignmentScore() <= 779)
    					{
    						System.out.println("The final grade for the student is a D.");
    					}
    				else if (testscore <= 224 && testscore >= 210 && ComputeAssignmentScore() >= 780 && ComputeAssignmentScore() <= 959)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (testscore <= 224 && testscore >= 210 && ComputeAssignmentScore() >= 900 && ComputeAssignmentScore() <= 1200)
    					{
    						System.out.println("The final grade for the student is a B.");
    					}
    				else if (testscore <= 239 && testscore >= 225 && ComputeAssignmentScore() <= 599)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (testscore <= 239 && testscore >= 225 && ComputeAssignmentScore() >= 600 && ComputeAssignmentScore() <= 719)
    					{
    						System.out.println("The final grade for the student is a D.");
    					}
    				else if (testscore <= 239 && testscore >= 225 && ComputeAssignmentScore() >= 720 && ComputeAssignmentScore() <= 899)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (testscore <= 239 && testscore >= 225 && ComputeAssignmentScore() >= 900 && ComputeAssignmentScore() <= 1139)
    					{
    						System.out.println("The final grade for the student is a B.");
    					}
    				else if (testscore <= 239 && testscore >= 225 && ComputeAssignmentScore() >= 1140 && ComputeAssignmentScore() <= 1200)
    					{
    						System.out.println("The final grade for the student is an A.");
    					}
    				else if (testscore >= 240 && testscore <= 254 && ComputeAssignmentScore() <= 599)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (testscore >= 240 && testscore <= 254 && ComputeAssignmentScore() >= 600 && ComputeAssignmentScore() <= 659)
    					{
    						System.out.println("The final grade for the student is a D.");
    					}
    				else if (testscore >= 240 && testscore <= 254 && ComputeAssignmentScore() >= 660 && ComputeAssignmentScore() <= 839)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (testscore >= 240 && testscore <= 254 && ComputeAssignmentScore() >= 840 && ComputeAssignmentScore() <= 1079)
    					{
    						System.out.println("The final grade for the student is a B.");
    					}
    				else if (testscore >= 240 && testscore <= 254 && ComputeAssignmentScore() >= 1080 && ComputeAssignmentScore() <= 1200)
    					{
    						System.out.println("The final grade for the student is an A.");
    					}
    				else if (testscore >= 255 && testscore <= 269 && ComputeAssignmentScore() <= 599)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (testscore >= 255 && testscore <= 269 && ComputeAssignmentScore() >= 600 && ComputeAssignmentScore() <= 779)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (testscore >= 255 && testscore <= 269 && ComputeAssignmentScore() >= 780 && ComputeAssignmentScore() <= 1019)
    					{
    						System.out.println("The final grade for the student is a B.");
    					}
    				else if (testscore >= 255 && testscore <= 269 && ComputeAssignmentScore() >= 1020 && ComputeAssignmentScore() <= 1200)
    					{
    						System.out.println("The final grade for the student is an A.");
    					}
    				else if (testscore >= 270 && testscore <= 284 && ComputeAssignmentScore() <= 599)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (testscore >= 270 && testscore <= 284 && ComputeAssignmentScore() >= 600 && ComputeAssignmentScore() <= 779)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (testscore >= 270 && testscore <= 284 && ComputeAssignmentScore() >= 780 && ComputeAssignmentScore() <= 899)
    					{
    						System.out.println("The final grade for the student is a B.");
    					}
    				else if (testscore >= 270 && testscore <= 284 && ComputeAssignmentScore() >= 900 && ComputeAssignmentScore() <= 1200)
    					{
    						System.out.println("The final grade for the student is an A.");
    					}
    				else if (testscore >= 285 && testscore <= 300 && ComputeAssignmentScore() <= 599)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (testscore >= 285 && testscore <= 300 && ComputeAssignmentScore() >= 600 && ComputeAssignmentScore() <= 719)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (testscore >= 285 && testscore <= 300 && ComputeAssignmentScore() >= 720 && ComputeAssignmentScore() <= 899)
    					{
    						System.out.println("The final grade for the student is a B.");
    					}
    				else if (testscore >= 285 && testscore <= 300 && ComputeAssignmentScore() >= 900 && ComputeAssignmentScore() <= 1200)
    					{
    						System.out.println("The final grade for the student is an A.");
    					}
    				System.out.println("                 ");
    			}
    	}

  9. #9
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    786
    Rep Power
    5

    Default

    hmm..check your conditions and the value of testscore..and whats about the ComputeAssignmentScore() ? why didnt you change it in the ComputeLetterGrade method too? :confused:

  10. #10
    BariMutation is offline Member
    Join Date
    Oct 2010
    Posts
    22
    Rep Power
    0

    Default

    I'm... not sure why I didn't change it lol But bear with me on this, the professor hasn't taught us any of this, so I'm really oblivious as to what I'm doing :( Here's where I'm at now... it obviously isn't working still.

    Java Code:
    import java.util.*;
    import java.util.Random;
    
    public class CourseGradeCalculator
    	{	
    		public static void main (String [] args)
    			{
    				Scanner scanner = new Scanner(System.in);
    				System.out.println("Please enter the number of students.");
    				int studentNumber = 0;
    					studentNumber=scanner.nextInt();
    					
    				for (int i=1; i<=studentNumber; i++)
    					{
    						System.out.println("Student " + i + ": ");
    						CourseGradeCalculator newInstance = new CourseGradeCalculator();
    							newInstance.ComputeAssignmentScore();
    							int assignmentscore = newInstance.ComputeAssignmentScore();
    							int testscore = newInstance.ComputeTestScore();
    							newInstance.ComputeLetterGrade(int testscore; int assignmentscore);
    					}
    			}	
    		public int ComputeAssignmentScore()
    			{
    				Scanner scanner = new Scanner(System.in);
    			
    				int finalAssignments = 0;
    				for (int j=1; j<=6; j++)
    					{
    						Random gradeGenerator = new Random();
    						int grade = gradeGenerator.nextInt(101);
    						System.out.println("Assignment " + j + ": " + grade);
    						finalAssignments += grade;
    					}		//End of Assignments Section
    				
    				int finalAttendance = 0;
    				for (int k=1; k<=1; k++)
    					{
    						Random gradeGenerator = new Random();
    						int grade = gradeGenerator.nextInt(26);
    						System.out.println("Attendance: " + grade);
    						finalAttendance += grade;
    					}	//End of Attendance Section
    				
    				int finalLabs = 0;
    				for (int l=1; l<=15; l++)
    					{
    						Random gradeGenerator = new Random();
    						int grade = gradeGenerator.nextInt(36);
    						System.out.println("Lab " + l + ": " + grade);
    						finalLabs += grade;
    					}	//End of Labs Section
    					
    				int finalQuizzes = 0;
    				for (int q=1; q<=1; q++)
    					{
    						Random gradeGenerator = new Random();
    						int grade = gradeGenerator.nextInt(51);
    						System.out.println("Quizzes: " + grade);
    					}
    				
    				int OverallAssignments = 0;
    				OverallAssignments = finalLabs + finalAttendance + finalAssignments;//Finalizes the overall assignment section
    					
    				return OverallAssignments;	
    			}
    			
    		public int ComputeTestScore()
    			{
    				int finalPAT = 0;
    				for (int n=1; n<=1; n++)
    					{
    						Random gradeGenerator = new Random();
    						int grade = gradeGenerator.nextInt(31);
    						System.out.println("PAT: " + grade);
    						finalPAT += grade;
    					}		//End of PAT Section
    				
    				int finalLOs = 0;
    				for (int m=1; m<=15; m++)
    					{
    						Random gradeGenerator = new Random();
    						int grade = gradeGenerator.nextInt(31);
    						System.out.println("LO "+ m + ": " + grade);
    						finalLOs += grade;
    					}		//End of LOs Section
    				
    				int finalMidterms = 0;
    				Random gradeGenerator = new Random();
    				for (int o=1; o<=2; o++)
    					{
    						int grade = gradeGenerator.nextInt(61);
    						System.out.println("Midterm "+ o + ": " + grade);
    						finalMidterms += grade;
    					}		//End of Midterms Section
    		
    				int finalfE = 0;
    				for (int p=1; p<=1; p++)
    					{
    						int grade = gradeGenerator.nextInt(121);
    						System.out.println("Final Exam: " + grade);
    						finalfE += grade;
    					}
    	
    				int OverallTests = 0;
    				OverallTests = finalfE + finalMidterms + finalPAT + finalLOs;//End of FinalExam Section
    				return OverallTests;
    			}
    			
    		public void ComputeLetterGrade(int testscore; int assignmentscore)
    			{
    				if (testscore <= 149)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (testscore <= 164 && testscore >= 150 && assignmentscore <= 779)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (testscore <= 164 && testscore >= 150 && assignmentscore <=1079 && assignmentscore >= 780)
    					{
    						System.out.println("The final grade for the student is a D.");
    					}
    				else if (testscore <= 164 && testscore >= 150 && assignmentscore <= 1200 && assignmentscore >= 1080)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (testscore <= 179 && testscore >= 165 && assignmentscore <= 719)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (testscore <= 179 && testscore >= 165 && assignmentscore <= 959 && assignmentscore >= 720)
    					{
    						System.out.println("The final grade for the student is a D.");
    					}
    				else if (testscore <= 179 && testscore >= 165 && assignmentscore >= 960 && assignmentscore <= 1200)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (testscore <= 194 && testscore >= 180 && assignmentscore <= 659)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (testscore <= 194 && testscore >= 180 && assignmentscore <=899 && assignmentscore >= 660)
    					{
    						System.out.println("The final grade for the student is a D.");
    					}
    				else if (testscore <= 194 && testscore >= 180 && assignmentscore <= 1139 && assignmentscore >= 900)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (testscore <= 194 && testscore >= 180 && assignmentscore <= 1200 && assignmentscore >= 1140)
    					{
    						System.out.println("The final grade for the student is a B.");
    					}
    				else if (testscore <= 209 && testscore >= 195 && assignmentscore <= 659)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (testscore <= 209 && testscore >= 195 && assignmentscore >= 660 && assignmentscore <= 839)
    					{
    						System.out.println("The final grade for the student is a D.");
    					}
    				else if (testscore <= 209 && testscore >= 195 && assignmentscore >= 840 && assignmentscore <= 1079)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (testscore <= 209 && testscore >= 195 && assignmentscore >= 1080 && assignmentscore <= 1200)
    					{
    						System.out.println("The final grade for the student is a B.");
    					}
    				else if (testscore <= 224 && testscore >= 210 && assignmentscore <= 599)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (testscore <= 224 && testscore >= 210 && assignmentscore >= 600 && assignmentscore <= 779)
    					{
    						System.out.println("The final grade for the student is a D.");
    					}
    				else if (testscore <= 224 && testscore >= 210 && assignmentscore >= 780 && assignmentscore <= 959)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (testscore <= 224 && testscore >= 210 && assignmentscore >= 900 && assignmentscore <= 1200)
    					{
    						System.out.println("The final grade for the student is a B.");
    					}
    				else if (testscore <= 239 && testscore >= 225 && assignmentscore <= 599)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (testscore <= 239 && testscore >= 225 && assignmentscore >= 600 && assignmentscore <= 719)
    					{
    						System.out.println("The final grade for the student is a D.");
    					}
    				else if (testscore <= 239 && testscore >= 225 && assignmentscore >= 720 && assignmentscore <= 899)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (testscore <= 239 && testscore >= 225 && assignmentscore >= 900 && assignmentscore <= 1139)
    					{
    						System.out.println("The final grade for the student is a B.");
    					}
    				else if (testscore <= 239 && testscore >= 225 && assignmentscore >= 1140 && assignmentscore <= 1200)
    					{
    						System.out.println("The final grade for the student is an A.");
    					}
    				else if (testscore >= 240 && testscore <= 254 && assignmentscore <= 599)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (testscore >= 240 && testscore <= 254 && assignmentscore >= 600 && assignmentscore <= 659)
    					{
    						System.out.println("The final grade for the student is a D.");
    					}
    				else if (testscore >= 240 && testscore <= 254 && assignmentscore >= 660 && assignmentscore <= 839)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (testscore >= 240 && testscore <= 254 && assignmentscore >= 840 && assignmentscore <= 1079)
    					{
    						System.out.println("The final grade for the student is a B.");
    					}
    				else if (testscore >= 240 && testscore <= 254 && assignmentscore >= 1080 && assignmentscore <= 1200)
    					{
    						System.out.println("The final grade for the student is an A.");
    					}
    				else if (testscore >= 255 && testscore <= 269 && assignmentscore <= 599)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (testscore >= 255 && testscore <= 269 && assignmentscore >= 600 && assignmentscore <= 779)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (testscore >= 255 && testscore <= 269 && assignmentscore >= 780 && assignmentscore <= 1019)
    					{
    						System.out.println("The final grade for the student is a B.");
    					}
    				else if (testscore >= 255 && testscore <= 269 && assignmentscore >= 1020 && assignmentscore <= 1200)
    					{
    						System.out.println("The final grade for the student is an A.");
    					}
    				else if (testscore >= 270 && testscore <= 284 && assignmentscore <= 599)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (testscore >= 270 && testscore <= 284 && assignmentscore >= 600 && assignmentscore <= 779)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (testscore >= 270 && testscore <= 284 && assignmentscore >= 780 && assignmentscore <= 899)
    					{
    						System.out.println("The final grade for the student is a B.");
    					}
    				else if (testscore >= 270 && testscore <= 284 && assignmentscore >= 900 && assignmentscore <= 1200)
    					{
    						System.out.println("The final grade for the student is an A.");
    					}
    				else if (testscore >= 285 && testscore <= 300 && assignmentscore <= 599)
    					{
    						System.out.println("The final grade for the student is an F.");
    					}
    				else if (testscore >= 285 && testscore <= 300 && assignmentscore >= 600 && assignmentscore <= 719)
    					{
    						System.out.println("The final grade for the student is a C.");
    					}
    				else if (testscore >= 285 && testscore <= 300 && assignmentscore >= 720 && assignmentscore <= 899)
    					{
    						System.out.println("The final grade for the student is a B.");
    					}
    				else if (testscore >= 285 && testscore <= 300 && assignmentscore >= 900 && assignmentscore <= 1200)
    					{
    						System.out.println("The final grade for the student is an A.");
    					}
    				System.out.println("                 ");
    			}
    	}

  11. #11
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    786
    Rep Power
    5

    Default

    :eek:

    newInstance.ComputeLetterGrade(int testscore; int assignmentscore);

    ---->

    newInstance.ComputeLetterGrade(testscore, assignmentscore); (without type and comma instead of semicolon)

    and

    public void ComputeLetterGrade(int testscore; int assignmentscore)

    ---->

    public void ComputeLetterGrade(int testscore, int assignmentscore) (comma instead of semikolon!!)

Similar Threads

  1. Times without dates.
    By JavaJuJitZu in forum Advanced Java
    Replies: 14
    Last Post: 01-17-2010, 10:54 PM
  2. Difference in seconds between two times
    By jazzy639 in forum New To Java
    Replies: 11
    Last Post: 09-26-2009, 06:58 PM
  3. Replies: 8
    Last Post: 06-07-2009, 02:29 AM
  4. Replies: 3
    Last Post: 10-02-2008, 05:48 AM

Posting Permissions

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