Revision: 62218
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at February 8, 2013 06:38 by eiger824
Initial Code
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;
static String cal=null;
public static void main(String[] args) {
int option;
String opt=getInput("Which test model are you correcting? 1-A; 2-B: ");
option=Integer.parseInt(opt);
switch(option){
case 1: cont=0;
cal = checkForTypedLength(cal);
calif=cal.toCharArray();
cont = updateCounters(cont, cal);
System.out.println("Result: "+cont+"/10");
break;
case 2:
cont=0;
cal = checkForTypedLength(cal);
calif=cal.toCharArray();
cont = updateCounters2(cont, cal);
System.out.println("Result: "+cont+"/10");
break;
}
}
public static int updateCounters(int cont, String cal) {
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;
}
public static int updateCounters2(int cont, String cal) {
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;
}
public static String checkForTypedLength(String cal) {
boolean go=true;
while(go==true){
cal=getInput("Enter answers (i.e.: acbbaabcddc; 0 if unanswered): ");
if(cal.length()!=10){
System.out.println("There are only 10 questions in the test!" +
" Please enter them correctly.");
}
else{
go=false;
}
}
return cal;
}
private static String getInput(String prompt) {
BufferedReader stdin = new BufferedReader(
new InputStreamReader(System.in));
System.out.print(prompt);
System.out.flush();
try {
return stdin.readLine();
} catch (Exception e) {
return "Error: " + e.getMessage();
}
}
}
Initial URL
http://programmingeiger824.blogspot.com
Initial Description
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.
Initial Title
Test-Type Exam Correction With Java
Initial Tags
java
Initial Language
Java