Results 1 to 7 of 7
  1. #1
    guinea222 is offline Member
    Join Date
    Sep 2014
    Posts
    10
    Rep Power
    0

    Default Java converting a percentag grade to a letter grade - not running

    I am trying to create a program that allows me to enter 5 students numeric grade (0-100) to a letter grade (A, B, C, D, F) and I CANNOT use an array. When I try to run my program it says main class not found, and when I change the it from a string to a void in the main method it does not work. I am not sure what I am doing wrong and needs to be fixed. Any help is appreciated! I have tried getting help from my professor and he thinks he is useful but he is not, and the other kids I have for helped are confused to. I just have no clue where to go, now.

    Java Code:
    import java.util.Scanner;
    
    public class Week3ControlStatements2 
    {
        public static String main(String[] args){
            int numberGrade = 0;
          
        
        int quotient = numberGrade / 10;
        int remainder = numberGrade % 10;
    
        // This will hold the final letter grade
        String letterGrade;
    
        switch (quotient) {
            case 10:
                // The student got a 100%, so just return A+
                return "A+";
            case 9:
                // 90-99 is an A
                letterGrade = "A"; break;
            case 8:
                // 80-89 is a B
                letterGrade = "B"; break;
            case 7:
                // 70-79 is a C
                letterGrade = "C"; break;
            case 6:
                // 60-69 is a D
                letterGrade = "D"; break;
            default:
                // Anything 59 or below is an F
                return "F";
        }
    
                return letterGrade;
    }
    }

  2. #2
    guinea222 is offline Member
    Join Date
    Sep 2014
    Posts
    10
    Rep Power
    0

    Default Re: Java converting a percentag grade to a letter grade - not running

    I have edited the code and switched it around trying another method. I have it working, my only problem is that I need be able to input 5 grades and it give be a letter grade for each one. I can only do one at a time, I am not sure what needs to be done. I tried a while loop and a for loop which did not work (may of had them in the wrong place).
    Java Code:
      public static void main(String[] args){
            {
    
    	int grade = 0;
        Scanner input = new Scanner(System.in);
           
                System.out.println("Enter : ");
    	    grade = input.nextInt();
           
             if (grade >= 90)
    		System.out.println ("Letter grade: A ");
    	else if (grade >= 80)
    		System.out.println ("Letter grade: B ");
    	else if (grade >= 70)
    		System.out.println ("Letter grade: C ");
    	else if (grade >= 60)
    		System.out.println ("Letter grade: D ");
    	else if (grade >= 0)
    		System.out.println ("Letter grade: F ");
    
    
    
    	if (grade > 100)
    		System.out.println ("Error input a Value between 0 - 100 ");
    	if (grade < 0)
    		System.out.println ("Error input a Value between 0 - 100 ");
    	 
            
    	
    	}
        }
    }

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Java converting a percentag grade to a letter grade - not running

    Stick all the code that is in your main( ... ) method now, in another method, say 'myMethod()'; i.e.

    Java Code:
    private static void myMethod() {
       // all your original code goes here ...
    }
    And change your main( ... ) method to this:

    Java Code:
    public static void main(String[] args) {
       for (int i= 1; i <= 5; i++)
          myMethod();
    }
    I'm sure you'll understand this modification ...

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  4. #4
    guinea222 is offline Member
    Join Date
    Sep 2014
    Posts
    10
    Rep Power
    0

    Default Re: Java converting a percentag grade to a letter grade - not running

    Thank you so much this was a big help! I have a question and I know its really simple. Is the program I wrote using the if else statements and array? I cannot use this on my problem and my professor is of no help. He tries and thinks he is...

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Java converting a percentag grade to a letter grade - not running

    Quote Originally Posted by guinea222 View Post
    Is the program I wrote using the if else statements and array?
    Is it what? I don't see arrays in your code and you don't need them; a sequence of if ... else if ... else statements can solve the problem nicely.

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  6. #6
    guinea222 is offline Member
    Join Date
    Sep 2014
    Posts
    10
    Rep Power
    0

    Default Re: Java converting a percentag grade to a letter grade - not running

    Thank you I typed that wrong I meant is it an array or contain any arrays? I did not think so but wanted to make sure.. Thank you so much again.

  7. #7
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    12

    Default Re: Java converting a percentag grade to a letter grade - not running

    Well, you should know what an array is and therefore be able to answer your own question.

Similar Threads

  1. to print a letter grade for a numerical GPA
    By 4uAngelique in forum New To Java
    Replies: 16
    Last Post: 04-14-2012, 08:01 AM
  2. Java Grade 11 Beginner Help
    By dharav in forum New To Java
    Replies: 3
    Last Post: 12-18-2011, 05:01 PM
  3. Replies: 1
    Last Post: 10-08-2010, 02:00 PM
  4. Is Java ready for Carrier Grade Applications?
    By Kate in forum Reviews / Advertising
    Replies: 0
    Last Post: 06-18-2010, 11:18 AM
  5. Help with JAVA (Grade Book)
    By Sara_21 in forum New To Java
    Replies: 3
    Last Post: 11-30-2009, 02:45 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
  •