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

Thread: What am I missing?

  1. #1
    Member
    Join Date
    Aug 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    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?

    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
    Member
    Join Date
    Jan 2012
    Location
    Hellas
    Posts
    284
    Thanks
    11
    Thanked 59 Times in 57 Posts

    Default Re: What am I missing?

    Hello jean28!

    You have in your code;
    else if (grade <= 4)
    		{
    			System.out.println("A +");
    		}
    So when you enter a grade that is less than or equal to 4 it prints A+. This is exactly what your code it is supposed to do.
    You should use intervals to accomplish what you want. For example, A+ will get a grade that is <= 4 AND > 3.8 (that's just an example you can make the intervals however you want.)

    Hope this helps.

Similar Threads

  1. What am I missing?
    By prgmrGrl in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 9th, 2012, 11:33 PM
  2. missing something so simple....help!
    By b094mph in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 17th, 2011, 10:12 PM
  3. Missing drivers?
    By mjpam in forum JDBC & Databases
    Replies: 5
    Last Post: September 6th, 2010, 08:00 PM
  4. Java error in password generator program
    By Lizard in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 16th, 2009, 07:49 PM
  5. [SOLVED] Java program to generate 10 random integers and then sum computed
    By Lizard in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 14th, 2009, 12:33 PM