View difference between Paste ID: Ctr02Ra9 and yGC9dyd4
SHOW: | | - or go back to the newest paste.
1
/**
2
 * Name: Rohit Kothur
3
 * Assignment: Group Project
4
 * School: Phoenix Country Day School
5
 * Date: 1/31/2012
6
 */
7
8
import java.io.*;
9
import java.util.*;
10
11
public class Group_Project {
12
13
	  // file input
14
  	private static FileInputStream inFile;
15
  	private static InputStreamReader inReader;
16
  	private static  BufferedReader reader;
17
  	private static StringTokenizer strTkn;
18
19
    public static void main(String[] args) throws IOException {
20
		String[] studentID = new String[127];
21
		String[] answers = new String[127];
22
		int[] numGrade = new int[127];
23
		char[] letGrade = new char[127];
24
25
    	initFile();
26
    	String answerKey = readAnswerKey();
27
    	readStudents(studentID, answers);
28
    	getGrades(answerKey, answers, numGrade, letGrade);
29
30
    	printStudent(studentID, numGrade, letGrade);
31
    	printClass(numGrade, letGrade);
32
33
    	inFile.close();
34
    }
35
36
    public static void initFile() throws IOException
37
  	{
38
	    inFile = new FileInputStream ("C:\\Users\\Reivei\\Desktop\\Computer Classes\\!!VHSAPCSData\\tfquizdata.txt"); // notice the double slash marks
39
	    inReader = new InputStreamReader(inFile);
40
	    reader = new BufferedReader(inReader);
41
  	}
42
43
  	public static String readAnswerKey() throws IOException
44
  	{
45
  		String answerKey = reader.readLine();
46
  		System.out.println(answerKey);
47
  		return answerKey;
48
    }
49
50
    public static void readStudents(String[] studentID, String[] answers) throws IOException
51
    {
52
    	String line;
53
    	for(int i = 0; i < studentID.length; i++)
54
    	{
55
    		line = reader.readLine();
56
    		strTkn = new StringTokenizer(line);
57
    		studentID[i] = strTkn.nextToken();
58
    		answers[i] = strTkn.nextToken();
59
    	}
60
    }
61
62
    public static void getGrades(String answerKey, String[] answers, int[] numGrade, char[] letGrade)
63
    {
64
		for(int i = 0; i < answers.length; i++)
65
		{
66
			int grade = 0;
67
			for(int j = 0; j < answers[i].length(); j++)
68
			{
69
				if(answers[i].charAt(j) == answerKey.charAt(j))
70
				{
71
					grade ++;
72
				}
73
			}
74
75
			numGrade[i] = grade;
76
		}
77
78
		for(int i = 0; i < letGrade.length; i++)
79
		{
80
			if(numGrade[i] == 10)
81
			{
82
				letGrade[i] = 'A';
83
			}
84
85
			else if(numGrade[i] == 9)
86
			{
87
				letGrade[i] = 'B';
88
			}
89
90
			else if(numGrade[i] == 8 || numGrade[i] == 7)
91
			{
92
				letGrade[i] = 'C';
93
			}
94
95
			else if(numGrade[i] == 6 || numGrade[i] == 5)
96
			{
97
				letGrade[i] = 'D';
98
			}
99
100
			else
101
			{
102
				letGrade[i] = 'F';
103
			}
104
		}
105
    }
106
107
	public static void printStudent(String[] studentID, int[] numGrade, char[] letGrade)
108
	{
109
		for(int i = 0; i < studentID.length; i++)
110
    	{
111
    		System.out.println("Student " + studentID[i] + " got " + numGrade[i] + " out of 10 questions right and received a(n) " + letGrade[i] + ".");
112
    	}
113
    	System.out.println();
114
	}
115
116
	public static void printClass(int[] numGrade, char[] letGrade)
117
	{
118
		System.out.println(numGrade.length + " students took this quiz.");
119
		System.out.println();
120
121
		int average = 0;
122
		for(int grade : numGrade)
123
		{
124
			average += grade;
125
		}
126-
		System.out.println("The class average was " + average + " out of ten.");
126+
127
128
		System.out.println("The class average was " + average + " out of 10.");
129
		System.out.println();
130
131
		int aCount = 0, bCount = 0, cCount = 0, dCount = 0, fCount = 0;
132
133
		for(char grade : letGrade)
134
		{
135
			if(grade == 'A')
136
			{
137
				aCount++;
138
			}
139
			if(grade == 'B')
140
			{
141
				bCount++;
142
			}
143
			if(grade == 'C')
144
			{
145
				cCount++;
146
			}
147
			if(grade == 'D')
148
			{
149
				dCount++;
150
			}
151
			if(grade == 'F')
152
			{
153
				fCount++;
154
			}
155
		}
156
157
		System.out.println(aCount + " students received A's.");
158
		System.out.println(bCount + " students received B's.");
159
		System.out.println(cCount + " students received C's.");
160
		System.out.println(dCount + " students received D's.");
161
		System.out.println(fCount + " students received F's.");
162
	}
163
}