-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMOS_EXCEL.java
More file actions
110 lines (94 loc) · 3.6 KB
/
Copy pathMOS_EXCEL.java
File metadata and controls
110 lines (94 loc) · 3.6 KB
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
package MOS;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import javax.swing.*;
public class Mos_Excel extends JDialog
{
List<Question> questions = new ArrayList<Question>();
int score=0;
ButtonGroup group = new ButtonGroup();
JButton btnOk = new JButton("Ok");
public Mos_Excel()
{
super();
setModal(true);
setLayout(new BoxLayout(getContentPane(),BoxLayout.Y_AXIS));
btnOk.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
setVisible(false);
}});
questions.add(new Question("Versi terbaru dari Microsoft Excel:", new String[]{"MICROSOFT EXCEL 2003","MICROSOFT EXCEL 2013","MICROSOFT EXCEL 2007","MICROSOFT EXCEL 2010"},"MICROSOFT EXCEL 2010"));
questions.add(new Question("Fungsi yang digunakan untuk mengira jumlah data:", new String[]{"Sum","Max","Min","Average"},"Sum"));
questions.add(new Question("Fungsi yang digunakan untuk mencari nilai terbesar:", new String[]{"Sum","Max","Min","Average"},"Max"));
questions.add(new Question("Fungsi yang digunakan untuk mencari nilai terkecil:", new String[]{"Sum","Max","Min","Average"},"Min"));
questions.add(new Question("Fungsi yang digunakan untuk mencari nilai purata:", new String[]{"Sum","Max","Min","Average"},"Average"));
}
public int startexcel()
{
int score=0;
for (Question q : questions)
{
displayQuestion(q);
if (group.getSelection().getActionCommand().equals(q.getCorrectAnswer()))
{
score++;
}
}
dispose();
return score;
}
private void displayQuestion(Question q)
{
getContentPane().removeAll();
for (Enumeration buttonGroup=group.getElements(); buttonGroup.hasMoreElements(); )
{
group.remove((AbstractButton)buttonGroup.nextElement());
}
JLabel questionText = new JLabel(q.getQuestion());
getContentPane().add(questionText);
for (String answer : q.getAnswers())
{
JRadioButton radio = new JRadioButton(answer);
radio.setActionCommand(answer);
group.add(radio);
getContentPane().add(radio);
}
getContentPane().add(btnOk);
pack();
setVisible(true);
}
public static void main(String args[])
{
Mos_Excel quiz = new Mos_Excel();
int score = quiz.startexcel();
JOptionPane.showMessageDialog(null,"Your score: "+score,"",JOptionPane.INFORMATION_MESSAGE);
}
class Question
{
String question="";
String[] answers;
String correctAnswer;
public Question(String question, String[] possibleAnswers, String correctAnswer)
{
this.question = question;
this.answers = possibleAnswers;
this.correctAnswer = correctAnswer;
}
public String getQuestion()
{
return question;
}
public String[] getAnswers()
{
return answers;
}
public String getCorrectAnswer()
{
return correctAnswer;
}
}
}