Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AbstractClass - more flexible grading #32

Open
jy95 opened this issue Oct 28, 2020 · 0 comments
Open

AbstractClass - more flexible grading #32

jy95 opened this issue Oct 28, 2020 · 0 comments

Comments

@jy95
Copy link
Contributor

jy95 commented Oct 28, 2020

Hello @AlexandreDubray,

If you want that exercise AbstractClass (and others in the future with this kind) to be more "tolerant" to students errors, here are a few tips on how to do it with an example :

  1. Replace all .class invocations by Class.forName() (that is what causes students to see message "You modified ..." )
  2. Add multiple Exception handlers (mainly ClassNotFoundException and NoSuchMethodError )

Example :

try {
   String classNameWithPackage = "templates.Shape";
   Class shapeClass = Class.forName(classNameWithPackage);
   Method my_method = shapeClass.getDeclaredMethod("getArea", double.class);
   // ... Some piece of code later ...
   throw new CustomGradingResult(TestStatus.SUCCESS,1, "You defined a class Shape with a method called getArea")
} catch(ClassNotFoundException err) {
   throw new CustomGradingResult(TestStatus.FAILED, 0, "Shape class not found");
} catch(NoSuchMethodError err) {
   throw new CustomGradingResult(TestStatus.FAILED, 0, "Shape method getArea cannot be found");
} catch(Exception err) {
   if (err instanceof CustomGradingResult) {
       throw err;
   }
   throw new CustomGradingResult(TestStatus.FAILED, 0, "Unexpected error");
}

PS: As I'm busy with work, I can't make any PR for a long time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant