I am wondering if there is a way to use a loop to display class information.
For example, if I have multiple instance created like,
Specimen a = new Specimen("1", "2", "3");
Specimen b = new Specimen("4", "5", "6");
and a toString method which would display my information in the desired way; is there any possible way to use a loop or while to print a.toString() and b.toString() and so on (c,d,e,f,g, etc) without having to continuously type a.toString(), b.toString, etc.
This is currently what my main method looks like
public static void main(String[]args){
Specimen SF11 = new Specimen("SF11", "Starfish", 10, 20 );
System.out.println(SF11.toString());
Specimen SU12 = new Specimen("SU12", "Sea Urchin", 12, 25);
System.out.println(SU12.toString());
SF11.setsCount(16); SF11.setsName("Blue Starfish"); SF11.setsTank(22);
System.out.print(SF11.toString() + "\n" + SU12.toString());
}
}