I need some help with a java program. I'm just in a beginners java class, so it's not too hard of a question, I just couldn't find the answers anywhere
I need to create multiple objects of a class which has methods and characteristics for different "problems" of a test. I need to declare many of these objects, yet I don't want about 3 lines repeating about 25 times. I think I can use a for loop to create these objects, but then I couldn't name the objects differently.
For example:
for (int curQuestion = 1; curQuestion < numOfQuestions; curQuestion++);
{
System.out.println ("Enter question" + curQuestion);
Question = scan.nextLine();
System.out.println ("Enter answer for question" + curQuestion);
Answer = scan.nextLine();
q = new Question (question, answer);
quiz.add (q);
}
each time the for loop loops, the entered values are used to create new object questions, which then get added to the next place in the array list. these question objects are all named "q" and I was wondering if that could actually work.
Can I create multiple objects of the same name with different properties to it?
(if there is an easier way, it would kinda have to be simple java; my teacher wouldn't want me using really anything more advanced than that stuff...)
