forked from BimalRajGyawali/hacktoberfest-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
QuizCheckResult.java
147 lines (121 loc) · 3.85 KB
/
QuizCheckResult.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import java.util.*;
class QuizCheckResult
{
public static final int PasswordLength = 8;
public static boolean isValidPassword(String password) {
if (password.length() < PasswordLength) return false;
int charCount = 0;
int numCount = 0;
for (int i = 0; i < password.length(); i++) {
char ch = password.charAt(i);
if (isNumeric(ch)) numCount++;
else if (isLetter(ch)) charCount++;
else return false;
}
return (charCount >= 2 && numCount >= 2);
}
public static boolean isLetter(char ch) {
ch = Character.toUpperCase(ch);
return (ch >= 'A' && ch <= 'Z');
}
public static boolean isNumeric(char ch) {
return (ch >= '0' && ch <= '9');
}
// creating array object.
char A[][],K[];
int S[],n;
void input()
{
// create object of scanner class.
Scanner sc = new Scanner(System.in);
// enter number of participants.
System.out.print("Enter number of participants : ");
n = sc.nextInt();
// condition of least and heighest input
if(n<4 || n>10)
{
// input the range here.
System.out.print("Input size out of range : ");
System.exit(0);
}
A = new char[n][5];
K = new char[5];
S = new int[n];
// enter the correct answer to check the answers of students.
System.out.println("\n* Enter answer of each participant row-wise in a single line *\n");
for(int i = 0; i<n; i++)
{
System.out.print("Participant "+(i+1)+" : ");
for(int j=0; j<5; j++)
{
A[i][j] = sc.next().charAt(0);
}
}
System.out.print("\nEnter Answer Key : ");
for(int i = 0; i<5; i++)
{
K[i] = sc.next().charAt(0);
}
}
// Function to calculate score of participant
void Score()
{
for(int i = 0; i<n; i++)
{
S[i] = 0;
for(int j=0; j<5; j++)
{
// Checking if Answer of the participants match with the key or not
if(A[i][j] == K[j])
{
S[i]++;
}
}
}
}
// function to print score.
void printScore()
{
int max = 0;
System.out.println("\nSCORES : ");
for(int i = 0; i<n; i++)
{
System.out.println("\tParticipant "+(i+1)+" = "+S[i]);
if(S[i]>max)
{
// Storing the Highest Score
max = S[i];
}
}
System.out.println();
System.out.println("\tHighest Score : "+max);
// Printing all those participant number who got highest score
System.out.println("\tHighest Scorers : ");
for(int i = 0; i<n; i++)
{
if(S[i] == max)
{
System.out.println("\t\t\tParticipant "+(i+1));
}
}
}
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
System.out.print(
"1. A password must have at least eight characters.\n" +
"2. A password consists of only letters and digits.\n" +
"3. A password must contain at least two digits \n" +
"Input a password (You are agreeing to the above Terms and Conditions.): ");
String s = input.nextLine();
if (isValidPassword(s)) {
System.out.println("Password is valid: " + s);
} else {
System.out.println("Not a valid password: " + s);
}
QuizCheckResult ob = new QuizCheckResult();
ob.input();
ob.Score();
ob.printScore();
}
}