Results 1 to 4 of 4
  1. #1
    tracy-london is offline Member
    Join Date
    Jan 2009
    Posts
    2
    Rep Power
    0

    Default I need help with my work assig Please

    Problem Specification
    Write a program that converts test marks (which are in percent, e.g. 45%) into a level code and description (e.g. P Pass, 40% - 50%). Implement the program in 2 stages:
     In stage one assign a single character level code based on the percentage value of a test score: an M for a score of 60% or above (Merit), a D for a score of 70% or above (Distinction) and so on (see ‘Table of Levels’ below). You should use an ‘if’ statement with a series of companion ‘else if’ statements, and a final ‘else’.
     In stage two use this letter in a ‘switch’ statement to add a description of the level achieved (e.g. for the letter ‘N’: A narrow, compensatable failure 35% - 39%.)

    If the value read is negative or greater than 100, print the message: "Error, invalid value"

    Method
     Complete the code for the full range of Levels possible D - F.
     Use an "if ... else if ... else " construct for stage one.
     Use a switch construct to convert the code to a String description in stage two.


    Table of Levels:
    D = Distinction (70% -100%)
    M = Merit (60% - 69%)
    P = Pass (40% - 59%)
    N = A narrow, compensatable failure (35% - 39%)
    F = A clear, non-compensatable failure (0% - 34%)

    Typical input / output:
    Typical input
    Enter percentage mark: 40
    Typical output
    A percentage mark of 41 is level P giving a Pass


    -----------------------------------------------------------------------
    public class Grade
    { /* Read a mark in the range 0 to 100,and output the corresponding grade.*/
    public static void main(String[] args)
    { ConsoleReader in =

    new ConsoleReader(System.in);
    System.out.print("Enter percentage mark: ");
    int mark = in.readInt();
    String grade;
    if (mark >= 70) { grade = "A"; }
    else if (mark >= 60) { grade = "B"; }
    else if (mark >= 50) { grade = "C"; }
    else if (mark >= 40) { grade = "D"; }
    else { grade = "F"; }
    System.out.println("Grade = " + grade);
    }
    }


    I am lost i m trying my best reading codes again & again but mow :( cant
    any one help would be much appreciated Please.

    Tracy

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Suggestions

    First thing is to understand the requirements:
    Stage one: assign a single character level code based on the percentage value of a test score.
    The sample code is assigning a String. To assign a character, you have to use the "char" type instead of the "String" type and it is represented by single quotes (ex: 'a'). See the following link:

    Characters (The Java™ Tutorials > Learning the Java Language > Numbers and Strings)

    Also, you have to find out if the % is invalid (negative or greater than 100). That probably should be your first comparation, followed by the comparations for valid percentages. something like:
    Java Code:
    if (% is less than 0 or % is more than 100)
    else if (% >= 70).. etc
    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    tracy-london is offline Member
    Join Date
    Jan 2009
    Posts
    2
    Rep Power
    0

    Default

    class GradeMark{
    public static void main(String args[]) {
    int mark; //variables
    char grade='x';
    String msg="x";
    System.out.println("Enter percentage mark: "); //read user input
    mark = UserInput.readInt();

    if (mark<-2){ //If the value read is negative or greater than 100, print the message: "Error, invalid value
    System.out.println ("Error invalid input");
    System.exit(0);
    }
    if((mark < 35) && (mark >-1)){ // if mark is less than 34 and over 0
    grade ='F';
    }
    else if ( mark <40){ // if mark is between 34-39
    grade = 'N';
    }
    else if ( mark <60){ // if mark is between 40-59
    grade = 'P';
    }
    else if ( mark <70){ // if mark is between 60-69
    grade = 'M';
    }
    else if ( mark <101){ // if mark is between 70-100
    grade = 'D';
    }
    else {
    System.out.println("Error, invalid input"); //print error message is incorrect percentage is entered
    System.exit(0);
    }
    switch (grade){ // switch statement for grading
    case 'F': msg = "clear, non-compensatable failure";
    break;
    case 'N': msg = "narrow, compensatable failure";
    break;
    case 'P': msg = "Pass";
    break;
    case 'M': msg = "Merit";
    break;
    case 'D': msg = "Distinction";
    break;
    }

    System.out.println(("A percentage mark of ")+ mark + (" is level ") + grade + (" giving a ") + msg); // Print Typical output

    } //end of method
    } //end of main method

    well its work fine & give me tipical output as well but still i can smell some thing wrong. dont know what
    Thats what i need for out put

    Typical input / output:
    Typical input
    Enter percentage mark: 40
    Typical output
    A percentage mark of 41 is level P giving a Pass
    But i cant output : A percentage mark of 40 is level P giving a Pass

    I can just hope you can help me
    Thanks for your time

  4. #4
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default OK, you tried...

    Java Code:
    if (mark<-2)
    In no way or form does the above mean "user input is less than 0 or is more than 100". First you have to check if it's less than zero (negative) and then check if it's more than 100:
    Java Code:
    if (input < 0 || input > 100)
    The sequence of grades in your first post was better... from greater to lesser. So after the above statement follow with the comparation of >= 70, then >= 60, etc.
    The char assignments look good.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. Just how do I get Java to actually work?
    By MickY G in forum New To Java
    Replies: 5
    Last Post: 11-19-2008, 03:50 AM
  2. Synchronization Doesn't seem to work
    By sherinpearl in forum Threads and Synchronization
    Replies: 1
    Last Post: 04-23-2008, 06:30 PM
  3. Will this applet ever work?
    By willemjav in forum Java Applets
    Replies: 4
    Last Post: 04-20-2008, 05:40 PM
  4. Pass by ref. A work around?
    By diRisig in forum New To Java
    Replies: 0
    Last Post: 02-05-2008, 07:25 PM
  5. how would i get this to work...?
    By deeadeed in forum New To Java
    Replies: 6
    Last Post: 12-06-2007, 02:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •