Results 1 to 2 of 2
  1. #1
    zoe
    zoe is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default What is the best way to represent range of number...

    Hi, I am new to JAVA and I am trying to write a simple program for a class I have, the one thing I am stuck on (and maybe I am just over-analyzing) is I have to calculate grades.

    For example, B = 79%-89% I am thinking that I should use something like this (in pseudo code):

    Java Code:
    if iFinalScore >79 && <89 then cFinalGrade=B
    I am not sure if this is the correct way to implement the "and" operator, or if it will work at all any thoughts?
    Thanks.

  2. #2
    fernando is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default

    This can be used if you want the final grade to be stored as a char.
    Java Code:
    char finalGrade;
    int grade;
    if(grade>=0 && grade<=69)finalGrade=='F';
    else if(grade>=70 && grade<=79)finalGrade=='C';
    else if(grade>=80 && grade<=89)finalGrade=='B';
    else 
    finalGrade=='A';
    Or as a string.
    Java Code:
    StringfinalGrade;
    int grade;
    if(grade>=0 && grade<=69)finalGrade="F";
    else if(grade>=70 && grade<=79)finalGrade="C";
    else if(grade>=80 && grade<=89)finalGrade="B";
    else 
    finalGrade="A";

Similar Threads

  1. The highest number
    By I-Shine in forum Java Applets
    Replies: 3
    Last Post: 02-13-2008, 06:05 AM
  2. line number
    By kazitula in forum New To Java
    Replies: 3
    Last Post: 11-21-2007, 11:27 PM
  3. Replies: 3
    Last Post: 11-18-2007, 08:41 PM
  4. how to know the number of the line
    By simon in forum New To Java
    Replies: 3
    Last Post: 08-01-2007, 05:59 PM
  5. Can I set a range in case statement?
    By christina in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 09:41 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
  •