1. Member Join Date
Jan 2009
Posts
2
Rep Power
0

## 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

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

System.out.print("Enter percentage mark: ");
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"; }
}
}

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

Tracy  Reply With Quote

2. ## 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  Reply With Quote

3. Member Join Date
Jan 2009
Posts
2
Rep Power
0

## public static void main(String args[]) {
int mark; //variables
String msg="x";
System.out.println("Enter percentage mark: "); //read user input

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
}
else if ( mark <40){ // if mark is between 34-39
}
else if ( mark <60){ // if mark is between 40-59
}
else if ( mark <70){ // if mark is between 60-69
}
else if ( mark <101){ // if mark is between 70-100
}
else {
System.out.println("Error, invalid input"); //print error message is incorrect percentage is entered
System.exit(0);
}
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  Reply With Quote

4. ## 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  Reply With Quote

#### Posting Permissions

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