Question: in java I need to Build a main method to test and display the functionality of the Set class you built. i have the set
in java I need to Build a main method to test and display the functionality of the Set class you built. i have the set class but i dont know how to create a main method to test it here is the set class
import java.util.*; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Set; public class Driver implements Set{ List r_set = null; //Create new driver public Driver() { r_set = new ArrayList(); } //Create new driver for set capacity public Driver(int initalCapacity){ r_set = new ArrayList(initalCapacity); } public Driver(Collection c){ r_set = new ArrayList(); if (c !=null){ for (Iterator itr = c.iterator(); itr.hasNext();){ Object obj = itr.next(); if ( !r_set.contains(obj) ) r_set.add(obj); } } } @Override public int size() { return r_set.size(); } @Override public boolean isEmpty() { return r_set.isEmpty(); } @Override public boolean contains(Object o) { return r_set.contains(o); } @Override public Iterator iterator() { return r_set.iterator(); } @Override//maybe public Object[] toArray() { return new Object[0]; } @Override public boolean add(Object o) { boolean added = false; if (!r_set.contains(o)){ r_set.add(o); added = true; } return added; } @Override public boolean remove(Object o) { return r_set.remove(o); } @Override public boolean addAll(Collection c) { boolean added = false; if (c !=null) { for (Iterator itr = c.iterator(); itr.hasNext();){ Object obj = itr.next(); if (!r_set.contains(obj) ){ r_set.add(obj); added = true; } } } return added; } @Override //clears the set public void clear() { r_set.clear(); } @Override public boolean removeAll(Collection c) { return r_set.removeAll(c); } @Override public boolean retainAll(Collection c) { return r_set.retainAll(c); } @Override public boolean containsAll(Collection c) { return r_set.containsAll(c); } @Override //Returns the set in an array public Object[] toArray(Object[] a) { return r_set.toArray(a); } public static void main(String[] args) { } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
