Object A instantiates Object B.
After the user interacts with Object B, I want to return back to Object A because Object A needs to use the user-determined results in Object B. User answers questions in Object B.
Is there anyway to do that without instantiating a new Object A and passing the results in a constructor? Or is that the best method? I'm curious because wouldn't instantiating two Objects of the same type be wasteful?
I don't want to use inner classes because in addition to keeping Object A short, I want to have other Objects be able to use the Assignment class.I am using GUI for user interface. //Object A== Main Page
//Homework 1
if(e.getSource()==task[0]){
try {
AssignmentA hw1= new AssignmentA("questions.txt", 0); //creates Assignment to do
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
//Homework 2 Button
else if(e.getSource()==task[1]){
try {
AssignmentA hw2= new AssignmentA("questions.txt",1);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
//Object B==Assignment A
-creates questions and answers
-user picks answers and Assignment A stores the grade for the assignment.
Here's the scenario: Object A is the Main Page that allows you to access different assignments through buttons and contains the overall grade after doing multiple assignments. Object B is an Assignment Class. When one button is clicked, the Object B is instantiated and the user has to answer questions. Once the user finishes the assignment, I want to be able to return to the Object A/Main Page with a new overall grade without creating a new Object A.
I don't want to use an inner class because I have other pages that want to use the Assignment Class as well.