Results 1 to 2 of 2
  1. #1
    orange4 is offline Member
    Join Date
    Aug 2011
    Posts
    1
    Rep Power
    0

    Default [Please Help] Grading Program

    This program is actually part of an assignment that does multiple things, but I'll remove the unnecessary parts. This program is designed to prompt the user for a grade. If the grade is A,B,C,D, or F, the program will ask for the next grade until the user enters Z. If the input is anything but a valid grade or Z, the program is supposed to display:
    "< (User Input) is NOT an acceptable grade>"
    and then prompt the user for the grade again.
    The problem is right now, when the program is run, it is not prompting the user for a grade and instead displays "< is NOT an acceptable grade>" over and over, and the program loops endlessly.
    Any suggestions?

    Code:
    Java Code:
    import java.util.Scanner;
    
    public class gradesloop{
    
    	public static void main (String [] args){
    
    
    		Scanner Reader = new Scanner(System.in);
    
    		String Grade;
    
    		Choice = 0;
    		TotalGrades = 0;PassGrades = 0; FailGrades = 0;PassRound = 0;
                    FailRound =0;StopLoop = 0;		
    		 Grade = "X";
    
    			System.out.print("Enter Grade #" + TotalGrades);
    			Grade = Reader.nextLine();
    
    			while (!("Z".equals(Grade))){
    
    			if ("A".equals(Grade)) {
    				TotalGrades ++;
    				PassGrades ++;
    }
    
    			else if ("B".equals(Grade)) {
    				TotalGrades ++;
    				PassGrades ++;
    
    }
    
    			else if ("C".equals(Grade)){
    				TotalGrades ++;
    				PassGrades ++;
    
    }
    
    			else if ("D".equals(Grade)){
    				TotalGrades ++;
    				PassGrades ++;
    }
    
    			else if ("F".equals(Grade)){
    				TotalGrades ++;
    				FailGrades ++;
    }
    			else{
    				System.out.println ("< " + Grade + " is NOT an acceptable grade>");
    }
    }
    			System.out.print("Enter Grade # " + TotalGrades);
    			Grade = Reader.nextLine();
    
    			while (("Z".equals(Grade)) && StopLoop == 0){
    
    				if (TotalGrades == 0){
    					System.out.println("0 students total");
    					System.out.println("0 students passed");
    					StopLoop = 1;
    }
    				else{
    					System.out.println(TotalGrades + " students total");
    					System.out.println(PassGrades + " students passed: ");
    					System.out.println(FailGrades + "stduents failed: ");
    					StopLoop = 1;
    }		
    }
    }
    Last edited by Norm; 08-18-2011 at 10:16 PM. Reason: Added code tags

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Any suggestions?
    Add a println to show what was read : println("Grade=" + Grade + "<");

    What does the program print out while it is looping? Add a few samples to show.
    Last edited by Norm; 08-18-2011 at 10:18 PM.

Similar Threads

  1. Replies: 2
    Last Post: 04-02-2011, 12:57 PM
  2. Replies: 13
    Last Post: 03-22-2011, 06:49 AM
  3. Java Program: Grading using Arrays [Help]
    By Sly Cooper in forum New To Java
    Replies: 1
    Last Post: 01-30-2011, 07:22 AM
  4. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 06:53 PM

Posting Permissions

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