Please take a look at this java code and help me understand what is wrong and ho
ID: 3544036 • Letter: P
Question
Please take a look at this java code and help me understand what is wrong and how to fix it?
public String add(String category, Question q) {
// Get the vector of questions from a category file
File f = new File(category);
f.createNewFile();
Vector<Question> Q = new Vector<Question>();
BufferedReader reader = new BufferedReader(new FileReader(f));
String line = null;
while((line = reader.readLine())!= null) {
Q.add(Question)line);
}
// Add the question object to the vector
Q.add(q);
// Save the vector back to the category file
Iterator i = new Iterator<Question>(Q);
FileWriter w = new FileWriter(f);
while(i.hasNext()) {
w.write((int)(i.next()));
}
w.flush();
w.close();
// Return the result of the save operation
return Q;
}
Instructions are including on what should happen
Explanation / Answer
I dont think that u can just typecast a string to Question object. Comment for more explanation