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

Thread: translate grade

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default translate grade

    this is my code:

    public String translateGrade(int score)
    { String grade = "F";
    if ( score >= 90 )
    { grade = "A"); }
    else { if ( score >= 80 )
    { grade = "B"; }
    else { if ( score >= 70 )
    { grade = "C"; }
    else { if ( score >= 60 )
    { grade = "D"; }

    }
    }
    }
    return grade;
    }


    AFTER EXECUTION DISPLAYED:::: error: class, interface, or enum expected


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: translate grade

    Can you post the full text of your program? Also, make sure you use proper formatting and the highlight tags, otherwise your code is impossible to read!
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Feb 2014
    Posts
    180
    Thanks
    0
    Thanked 48 Times in 45 Posts

    Default Re: translate grade

    Please ensure you apply a good and consistent code convention for the format and indentation of your code. It can make errors like this more obvious to you, especially if you're not using an IDE like Eclipse or NetBeans.

    Do make an effort to look through this: Code Conventions for the Java Programming Language: Contents , and in particular the "7.4 if, if-else, if else-if else Statements" section at Code Conventions for the Java Programming Language: 7. Statements (the reason will become obvious below.)

    Your code, if formatted properly, would look like this:
    public String translateGrade(int score) {
        String grade = "F";
        if (score >= 90) {
            grade = "A");
        }
        else {
            if (score >= 80) {
                grade = "B";
            }
            else {
                if (score >= 70) {
                    grade = "C";
                }
                else {
                    if (score >= 60) {
                        grade = "D";
                    }
     
                }
            }
        }
        return grade;
    }

    Pay attention to this line:
    grade = "A");

    As KevinWorkman implied there may also be other syntactical errors in the rest of your code. Hopefully with good formatting you'll be able to find them yourself (if any).

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: translate grade

    You aren't following this tutorial, are you? :p
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Translate code
    By Jdino23 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: December 7th, 2013, 12:59 PM
  2. Web Service for translate
    By mija in forum Java Theory & Questions
    Replies: 0
    Last Post: September 19th, 2012, 01:57 PM
  3. [SOLVED] Google translate API
    By vozmen in forum Java ME (Mobile Edition)
    Replies: 8
    Last Post: December 14th, 2011, 07:06 AM
  4. [SOLVED] Google translate api
    By vozmen in forum Java ME (Mobile Edition)
    Replies: 2
    Last Post: December 14th, 2011, 05:02 AM
  5. Help to translate from C to java
    By ighor10 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 27th, 2010, 07:36 AM