Skip to content

Instantly share code, notes, and snippets.

@portablejim
Created August 12, 2016 04:59
Show Gist options
  • Save portablejim/e3b7a6b18bc9d003d556c7d560702ec8 to your computer and use it in GitHub Desktop.
Save portablejim/e3b7a6b18bc9d003d556c7d560702ec8 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
class Grade {
double mark;
String grade;
/** Construct a Grade with a specified mark*/
public Grade(double m) {
mark = m;
}
/** Return the obtained grade*/
public String getGrade() {
if (mark >= 85 && mark <= 100) {
grade = "High Distinction";
} else if (mark >= 75 && mark < 84) {
grade = "Distinction";
} else if (mark >= 65 && mark < 75) {
grade = "Credit";
} else if (mark >= 50 && mark < 65) {
grade = "Pass";
} else if (mark >= 0 && mark < 50) {
grade = "Fail";
} else {
grade = "Mark does not match";
}
return grade;
}
}
public class GradeCal {
public static void main(String[] args) {
//declare scanner object to read the keyboard
Scanner input = new Scanner(System.in);
//reads mark
System.out.print("Enter mark: ");
Double examMark = input.nextDouble();
Grade ob = new Grade(examMark);
System.out.println("You got " + ob.mark + " mark so your grade is " +
ob.getGrade());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment