This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I am a complete noob(to this site and programming), but I did read the posting etiquette beforehand, so here goes...
This is for an assignment in my Beginning Java programming course. The current focus topic is polymorphism, and reinforcing how to use ArrayLists.
Project Requirements are:
-An abstract superclass with vars for general student data(student name, student id, etc.) and one abstract method.
-An interface with 2 methods.
-3 sub classes that implement the interface(elementarySchool, middleSchool, highSchool).
-Each sub class has to have one instance variable that is unique to that sub-class.
-A launcher class that will use an InputHelper to prompt the user for the information about the student, store the students in an ArrayList, and then loop through the ArrayList and display the student info.
The part I am struggling with at the moment is:
The ArrayList will be cast to hold objects of the super class, but I won't know what sub class of object I am storing until the user inputs it. Then I have to ask the user for input unique to that class. I am trying to compile Part2StudentList class where I create the ArrayList and prompt the user for input, and am getting this compile error-
Part2StudentList.java:41: cannot find symbol
symbol : method setId(java.lang.String)
location: class ElementarySchool
on every line in my "if" statement in that class, which is as follows:
Here is the code from my other classes, if it would be useful:
Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.
You can go back and change your post to add code tags by clicking the button on your post.