Results 1 to 5 of 5
  1. #1
    jean28 is offline Member
    Join Date
    Aug 2012
    Posts
    16
    Rep Power
    0

    Default What am I missing?

    Hey guys. I am trying to write a program that approximates certain values to a grade, but whenever I put a value below 4 I always get an output of A+. What's am I missing?

    Java Code:
    public class Grade 
    {
    	private double grade;
    
    	public Grade (double g)
    	{
    		grade = g;
    	}
    
    	public void getNumericCode()
    	{
    		
    		if (grade > 4)
    		{
    			System.out.println("You are smart, but not THAT smart!");
    		}
    		
    		
    		else if (grade <= 4)
    		{
    			System.out.println("A +");
    		}
    		
    		
    		else if (grade <= 3.8)
    		{
    			System.out.println("A");
    		}
    		
    		
    		else if (grade <= 3.2)
    		{
    			System.out.println("A -");
    		}
    		
    		
    		else if (grade <= 3)
    		{
    			System.out.println("B +");
    		}
    		
    		
    		else if (grade <= 2.8)
    		{
    			System.out.println("B");
    		}
    		
    
    		
    		else if (grade <= 2.2)
    		{
    			System.out.println("B -");
    		}
    		
    		
    		else if (grade <= 2)
    		{
    			System.out.println("C +");
    		}
    		
    		
    		else if (grade <= 1.8)
    		{
    			System.out.println("C");
    		}
    		
    		
    		else if(grade <= 1.2)
    		{
    			System.out.println("C -");
    		}
    		
    		
    		else if (grade <= 1)
    		{
    			System.out.println("D +");
    		}
    		
    		
    		else if (grade <= 0.8)
    		{
    			System.out.println("D");
    		}
    
    		
    		else if (grade <= 0.2)
    		{
    			System.out.println("D -");
    		}
    		
    		else if (grade >= 0)
    		{
    			System.out.println("F");
    		}
    		
    		else 
    		{
    			System.out.println("Not a valid grade.");
    		}
    	}
    }

  2. #2
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    392
    Rep Power
    4

    Default Re: What am I missing?

    Java Code:
            else if (grade <= 4)
            {
                System.out.println("A +");
            }
    That's what you're telling it to do.

  3. #3
    jean28 is offline Member
    Join Date
    Aug 2012
    Posts
    16
    Rep Power
    0

    Default Re: What am I missing?

    So I flip it from bottom to top??

  4. #4
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    392
    Rep Power
    4

    Default Re: What am I missing?

    Try it and see if it works!

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: What am I missing?

    Additionally, a method named getNumericCode() would be expected to return the numeric code, not print it. A better name might be showNumericCode().

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. org.j3d is missing...
    By LinuxDev@Flanders in forum Java Gaming
    Replies: 3
    Last Post: 07-23-2012, 12:31 PM
  2. What am I missing here?
    By PuppetJacks in forum New To Java
    Replies: 4
    Last Post: 07-01-2012, 11:16 AM
  3. What am I missing here..?
    By andrew_smiley in forum New To Java
    Replies: 5
    Last Post: 02-22-2012, 01:47 PM
  4. missing info
    By java-noob in forum New To Java
    Replies: 2
    Last Post: 04-20-2010, 09:55 AM
  5. Help; Missing JButtons
    By Cyprusice in forum New To Java
    Replies: 3
    Last Post: 01-10-2010, 11:50 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
  •