/ Published in: Java
A simple way of correcting tests with Java. In this piece of code I just defined two possible models or answers, they're all random, but the only thing needed is to update them with valid answers. The length of the test? I just did it for a 10-question test, but it can naturally be extended to the number of answers the teacher may want.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
package com.santi; import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { static char [] calif; static char [] answers = {'a','b','b','c','a','a','d','d','c','b'}; //example1 of right answers static char [] answers2 = {'b','b','c','a','a','b','d','b','a','c'};//example2 of right answers int result; static int cont; int option; switch(option){ case 1: cont=0; cal = checkForTypedLength(cal); calif=cal.toCharArray(); cont = updateCounters(cont, cal); break; case 2: cont=0; cal = checkForTypedLength(cal); calif=cal.toCharArray(); cont = updateCounters2(cont, cal); break; } } for(int i=0;i<cal.length();i++){ if(calif[i]==answers[i]){ cont++; } else if(calif[i]=='0'){ } else if(calif[i]!=answers[i]){ cont--; } } return cont; } for(int i=0;i<cal.length();i++){ if(calif[i]==answers2[i]){ cont++; } else if(calif[i]=='0'){ } else if(calif[i]!=answers2[i]){ cont--; } } return cont; } boolean go=true; while(go==true){ cal=getInput("Enter answers (i.e.: acbbaabcddc; 0 if unanswered): "); if(cal.length()!=10){ " Please enter them correctly."); } else{ go=false; } } return cal; } try { return stdin.readLine(); return "Error: " + e.getMessage(); } } }
URL: http://programmingeiger824.blogspot.com