-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhysicsModifyFillInTheBlank.java
186 lines (160 loc) · 6.8 KB
/
PhysicsModifyFillInTheBlank.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author abhiram
*/
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
public class PhysicsModifyFillInTheBlank extends java.awt.Frame {
/**
* Creates new form InsertPhyFillInTheBlank
*/
int questionNumber;
public PhysicsModifyFillInTheBlank(int questionNumberToBeModified) {
questionNumber = questionNumberToBeModified;
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
lblQuestion = new java.awt.Label();
lblAnswer = new java.awt.Label();
txtQuestion = new java.awt.TextField();
txtAnswer = new java.awt.TextField();
lblDisplay = new java.awt.Label();
btnModify = new java.awt.Button();
btnBack = new java.awt.Button();
setName("Modify Physics Fill in the Blank"); // NOI18N
setTitle("Modify Physics Fill in the Blank");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
setLayout(new FlowLayout());
setSize(1000,1000);
lblQuestion.setText("Question");
add(lblQuestion);
lblQuestion.setBounds(50, 71, 54, 20);
lblAnswer.setText("Answer");
add(lblAnswer);
lblAnswer.setBounds(50, 127, 45, 20);
add(txtQuestion);
txtQuestion.setBounds(130, 71, 145, 20);
add(txtAnswer);
txtAnswer.setBounds(130, 127, 145, 20);
lblDisplay.setText("Modify Fill in the Blank Question");
add(lblDisplay);
lblDisplay.setBounds(88, 20, 177, 20);
btnModify.setLabel("Modify");
add(btnModify);
btnModify.setBounds(104, 204, 50, 24);
btnModify.addActionListener(new ButtonClickListener());
btnModify.setActionCommand("modify");
btnBack.setLabel("back");
add(btnBack);
btnBack.setBounds(302, 248, 42, 24);
btnBack.setActionCommand("back");
btnBack.addActionListener(new ButtonClickListener());
setLayout(null);
}// </editor-fold>//GEN-END:initComponents
/**
* Exit the Application
*/
private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
System.exit(0);
}//GEN-LAST:event_exitForm
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new PhysicsInsertFillInTheBlank().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private java.awt.Button btnModify;
private java.awt.Button btnBack;
private java.awt.Label lblAnswer;
private java.awt.Label lblDisplay;
private java.awt.Label lblQuestion;
private java.awt.TextField txtAnswer;
private java.awt.TextField txtQuestion;
String filenameQuest;
String filenameAns;
// End of variables declaration//GEN-END:variables
public class ButtonClickListener implements ActionListener{
public void actionPerformed(ActionEvent e){
String command = e.getActionCommand();
if(command.equals("back")){
btnBack.getParent().setVisible(false);
new PhysicsModifyQuestion().setVisible(true);
}
else{
if(Subject.Subject.equals("phy")){
filenameQuest = ("PhysicsQuestions.txt");
filenameAns = ("PhysicsAnswers.txt");
}
if(Subject.Subject.equals("chem")){
filenameQuest = ("ChemistryQuestions.txt");
filenameAns = ("ChemAnswers.txt");
}
try{
//storing questions in file
FileReader fileReaderQuest = new FileReader(filenameQuest);
BufferedReader bufferedReaderQuest = new BufferedReader(fileReaderQuest);
FileReader fileReaderAns = new FileReader(filenameAns);
BufferedReader bufferedReaderAns = new BufferedReader(fileReaderAns);
int answerNumber = questionNumber;
String strQuest;
String strAns;
String strQuestionNumber = String.valueOf(questionNumber);
String newQuestion = strQuestionNumber + "." + txtQuestion.getText().toString()+ " -Fill in the blank";
String newAnswer = strQuestionNumber + "." + txtAnswer.getText().toString();
ArrayList<String> StringOfQuestions = new ArrayList<String>();
ArrayList<String> StringOfAnswers = new ArrayList<String>();
while((strQuest = bufferedReaderQuest.readLine())!=null){
StringOfQuestions.add(strQuest);
}
while((strAns=bufferedReaderAns.readLine())!=null){
StringOfAnswers.add(strAns);
}
FileWriter fileWriterQuest = new FileWriter(filenameQuest,false);
BufferedWriter bufferedWriterQuest = new BufferedWriter(fileWriterQuest);
FileWriter fileWriterAns = new FileWriter(filenameAns,false);
BufferedWriter bufferedWriterAns = new BufferedWriter(fileWriterAns);
try{
StringOfQuestions.set((questionNumber-1),newQuestion);
StringOfAnswers.set((questionNumber-1),newAnswer);
for(int i=0;i<StringOfQuestions.size();i++){
bufferedWriterQuest.write(StringOfQuestions.get(i));
bufferedWriterQuest.newLine();
bufferedWriterAns.write(StringOfAnswers.get(i));
bufferedWriterAns.newLine();
}
bufferedWriterQuest.close();
bufferedWriterAns.close();
}
catch(IOException ex){
System.out.println("Questions list is empty");
}
}
catch(IOException ex){
System.out.println("error");
}
}
}
}
}