Results 1 to 2 of 2
- 10-10-2011, 07:57 AM #1
Member
- Join Date
- Oct 2011
- Posts
- 1
- Rep Power
- 0
ArrayList must contain unique objects (Inheritance)
I am new to Java, I am woring on learning inheritance.
I am creating an abstract class called Thing.
I have to put this requirement in, Please could somebody help me with Syntax
Thing will have the following private class field:
• Things, an ArrayList defined with a Thing generic. This ArrayList must be maintained as Thing objects are constructed. This ArrayList must contain all unique objects for which (object instanceof Thing) is true. Each time an object for which (object instanceof Thing) is true is constructed, a reference to that object must be put in the ArrayList, if that object does not already exist in the ArrayList. The Thing equals method will be used to test if the object is not unique, i.e., already exists in the ArrayList. Your code must not useany object casts and must not use any instance of operator.
Thank you,Java Code:import java.util.*; public abstract class Thing { public String iName = new String(); private ArrayList<Thing> iThings = new ArrayList<Thing>(); public static void main(String[] args) { Thing vehicle1 = new Vehicle(); } public Thing(String name) { iName = name; } public String getName() { return iName; } public abstract void show(); public abstract boolean equals(Thing b); public void showThings() { System.out.println("Things"); show(); } }
urpalshuLast edited by DarrylBurke; 10-10-2011 at 04:04 PM.
- 10-10-2011, 04:03 PM #2
Similar Threads
-
Unique data check in a 2d array using objects
By sarevok9 in forum New To JavaReplies: 6Last Post: 04-20-2011, 02:57 AM -
ArrayList with Objects the right approach?
By scheffetz in forum New To JavaReplies: 1Last Post: 03-25-2011, 09:26 AM -
Arbitrary number of objects, each with a unique name.
By providence in forum New To JavaReplies: 8Last Post: 02-23-2011, 01:12 AM -
Help with objects in ArrayList
By BiteMuncher in forum New To JavaReplies: 7Last Post: 02-21-2011, 11:55 AM -
ArrayList with different objects? Help
By xtrmi in forum New To JavaReplies: 4Last Post: 02-27-2009, 08:51 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks