aspose file tools*
The moose likes Beginning Java and the fly likes ArrayList with abstract superclass, interface, and sub-classes with unique variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ArrayList with abstract superclass, interface, and sub-classes with unique variables" Watch "ArrayList with abstract superclass, interface, and sub-classes with unique variables" New topic
Author

ArrayList with abstract superclass, interface, and sub-classes with unique variables

John Sannito
Greenhorn

Joined: Apr 19, 2009
Posts: 7
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-

H:\projects\src\java111\project4>javac *.java
Part2StudentList.java:41: cannot find symbol
symbol : method setId(java.lang.String)
location: class ElementarySchool
newElementarySchool.setId(id);

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:


===================================

======================================

=================================================

========================================

=======================================
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
John Sannito
Greenhorn

Joined: Apr 19, 2009
Posts: 7
OK, thanks.
Amy Crowley
Greenhorn

Joined: Apr 19, 2009
Posts: 6
You should take a look at your access modifiers for id and setId - private access only goes so far (does not extend to subclasses). I think 'protected' access may be what you're after.
John Sannito
Greenhorn

Joined: Apr 19, 2009
Posts: 7
Thanks, That helped. I can compile it now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ArrayList with abstract superclass, interface, and sub-classes with unique variables