Hi, I have a program that I am writing. It allows the user to track player stats through a series of input and then stores those stats to an arraylist. Currently, I have added two two more sports so now I am up to three and I need to store all of these stats into an arraylist. I need to do it with polymorphism and not by having three seperate arraylists in the main method. How would I go about changing this so I am only using one array list.
I think what they mean with that you have to do it with polymorphism is this: you create a superclass, for example a class named Sport, and then you create subclasses of that for your specific kinds of sports. For example Baseball extends Sport, etc.
Then you create one ArrayList which holds elements of type Sport: List<Sport> sports = new ArrayList<Sport>();. Because Baseball is a Sport, you can put Baseball objects into this list, as well as any other objects of which the class extends Sport.