The SetInterface interface describes a set, a data structure similar to a bag ex
ID: 3869977 • Letter: T
Question
The SetInterface interface describes a set, a data structure similar to a bag except that it does not allow duplicates. It is a generic interface that declares abstract methods for adding an item, removing an item (specified or unspecified), checking if the set is empty, determining the number of items in the set, and fetching the items from the set into an array. You should not modify this interface.
The SetFullException class is included to allow potential implementations of SetInterface that have a fixed capacity. Your implementation should not be fixed capacity, and thus should not throw this exception.
The ProfileInterface interface describes a social network user’s profile. It declares abstract methods for setting and getting the user’s name and “about me” blurb, following other profiles, returning an array of the profile’s followed profiles, and recommending a new user to follow based on this profile’s “followed by those I follow” set. You should not modify this interface.
The SocialClient class is a sample client of both Set and Profile. It is a social networking simulator that allows the user to carry out following, unfollowing, etc. on a simple social network. This class maintains a set of profiles (stored as SetInterface. It also stores its data in a file (SocialClientData.bin) when quitting from the menu so that it can restore this data when it is run again. As noted above, this code is provided only as an example, and may not test all functionality of the required classes.
Tasks 3.1 Implement Set, 50 points
Develop the generic class, Set<E>, a dynamic-capacity array-based implementation of the Set ADT described in SetInterface<E>. Include this class in package cs.a1. Read the interface carefully (including comments) to ensure you implement it properly; it will be graded using a client that assumes all of the functionality described in the SetInterface, not just the behavior demonstrated in SocialClient!
You must include a constructor public Set(int capacity) that initializes the array to the specified initial capacity, and a constructor public Set() that uses a reasonable default initial capacity. Finally, you should provide a constructor public Set(E[] entries) that initializes the set with the provided entries. Note that this constructor should still create its own backing array, and not adopt the argument as a data member; it must also skip all duplicates and null values in the provided array. Whenever the capacity is reached, the array should resize, using the techniques discussed in lecture (i.e., you should never throw SetFullException).
Method Points: Set() 3, Set(int) 3, Set(E[]) 6, int getCurrentSize() 2, boolean isEmpty() 2, boolean add(E) 6, boolean remove(E) 6, E remove() 5, void clear() 4, boolean contains(E) 5, E[] toArray() 8
3.2 Implement Profile, 50 points
Develop the Profile class, an implementation of the ADT described in ProfileInterface. Include this class in package cs.a1. Read the interface carefully (including comments) to ensure you implement it properly. As with Set, it will be graded using a client that expects the functionality described in its interface. The Profile class should be a client of the Set data structure. Use composition with your Set<E> class to store the followees (the profiles that this profile is following) as a data member of type Set<Profile> or Set<ProfileInterface>.
You must include a constructor public Profile() that initializes the name and “about me” blurb to be empty strings, and a constructor public Profile(String name, String about) that initializes these data members with the specified values. In the latter, you must check for null values for both, and replace any null value with an empty string.
Method Points Profile() 2, Profile(String, String) 4, void setName(String) 4, String getName() 2, void setAbout(String) 4, String getAbout() 2, boolean follow(ProfileInterface) 7, boolean unfollow(ProfileInterface) 7, ProfileInterface[] following(int) 8, ProfileInterface recommend() 10
3.3 Testing
SocialClient is provided as an example client of the Profile and Set classes. It does not exhaustively test the functionality of these classes. You are responsible for ensuring your implementations work properly in all cases, even those not tested by SocialClient, and follow the ADTs described in the provided interfaces. Thus, it is highly recommended that you write additional test client code to test all of the corner cases described in the interfaces. For help getting started, re-read the section of the textbook starting at Chapter 2.16.
Note: For functionality that cannot be tested (e.g., methods that crash, cannot be compiled), up to 1/2 points will be awarded by inspection. At this level, turning in code that crashes or does not compile is not acceptable and will not yield success.
SetFullException.java
ProfileInterface.java
SocialClient.java
SetInterface.java
Explanation / Answer
Below is your code:-
Profile.java
public class Profile implements ProfileInterface {
private String newName;
private String newAbout;
Set<Profile> followingSet;
private int maxFollowers = 1000;
// constructor 1
public Profile() {
this.newName = "";
this.newAbout = "";
followingSet = new Set<Profile>(maxFollowers);
}
// constructor 2
public Profile(String name, String about) {
this.newName = name;
this.newAbout = about;
// checks for null values for newName and newAbout - if null,
// initializes them to empty string
if (this.newName == null) {
this.newName = "";
}
if (this.newAbout == null) {
this.newAbout = "";
}
followingSet = new Set<Profile>(maxFollowers);
}
@Override
public void setName(String newName) throws IllegalArgumentException {
if (newName == null) {
throw new IllegalArgumentException("Name entered is not valid.");
} else {
this.newName = newName;
}
}
@Override
public String getName() {
return this.newName;
}
@Override
public void setAbout(String newAbout) throws IllegalArgumentException {
if (newAbout == null) {
throw new IllegalArgumentException("About me section is not valid.");
} else {
this.newAbout = newAbout;
}
}
@Override
public String getAbout() {
return this.newAbout;
}
@Override
public boolean follow(ProfileInterface other) {
boolean result = true;
try {
result = this.followingSet.add((Profile) other);
} catch (SetFullException e) {
System.out.println("SetFullException caught.");
}
return result;
}
@Override
public boolean unfollow(ProfileInterface other) {
boolean result = false;
result = this.followingSet.remove((Profile) other);
return result;
}
@Override
public ProfileInterface[] following(int howMany) {
// checking to see if howMany is bigger than the array and if so, only
// print the number of values available in array
if (howMany > this.followingSet.getCurrentSize()) {
howMany = this.followingSet.getCurrentSize();
}
Object[] followingArr = new Object[howMany];
followingArr = this.followingSet.toArray();
ProfileInterface[] returnArr = new ProfileInterface[howMany];
// cast each item of following set to type ProfileInterface
for (int x = 0; x < howMany; x++) {
returnArr[x] = (ProfileInterface) followingArr[x];
}
return returnArr;
}
@Override
public ProfileInterface recommend() {
ProfileInterface suggestedFriend = null;
// creates array of profiles of friends that one of your friends follows
ProfileInterface[] friendsOfFriends = new ProfileInterface[100];
// creates an array of profiles that you already follow to compare
// against
ProfileInterface[] currentFriends = this.following(followingSet.getCurrentSize());
friendsOfFriends = currentFriends[0].following(maxFollowers);
for (int i = 0; i < currentFriends.length; i++) {
friendsOfFriends = currentFriends[i].following(followingSet.getCurrentSize());
}
for (int i = 0; i < friendsOfFriends.length; i++) {
// checking to see if you are already friends with this other
// persons friend
// if you arent, suggests you add this person
if (this.followingSet.contains((Profile) friendsOfFriends[i]) == false
&& this.equals((Profile) friendsOfFriends[i]) == false) {
suggestedFriend = friendsOfFriends[i];
break;
}
}
return suggestedFriend;
}
}
ProfileInterface.java
// There are no abstract methods to override in this interface, but declaring
// that you implement it allows objects of this type to be written out to disk
// or over the network.
import java.io.Serializable;
/**
* ProfileInterface describes a social media profile. It stores a user's name,
* "about me" blurb, and a set of profiles that the user follows. It can also
* suggest new profiles to follow based on the "followers of followers"
* technique.
*/
public interface ProfileInterface extends Serializable {
/**
* Sets this profile's name.
*
* <p> If newName is not null, then setName modifies this profile so that
* its name is newName. If newName is null, then setName throws
* IllegalArgumentException without modifying the profile, for example:
*
* <p> {@code throw new IllegalArgumentException("Name cannot be null")}
*
* @param newName The new name
* @throws IllegalArgumentException If newName is null
*/
public void setName(String newName) throws IllegalArgumentException;
/**
* Gets this profile's name.
*
* @return The name
*/
public String getName();
/**
* Sets this profile's "about me" blurb.
*
* <p> If newAbout is not null, then setAbout modifies this profile so that
* its about blurb is newAbout. If newAbout is null, then setAbout throws
* IllegalArgumentException without modifying the profile.
*
* @param newAbout The new blurb
* @throws IllegalArgumentException If newAbout is null
*/
public void setAbout(String newAbout) throws IllegalArgumentException;
/**
* Gets this profile's "about me" blurb
*
* @return The blurb
*/
public String getAbout();
/**
* Adds another profile to this profile's following set.
*
* <p> If this profile's following set is at capacity, or if other is null,
* then follow returns false without modifying the profile. Otherwise, other
* is added to this profile's following set and follow returns true. If this
* profile already followed other, then follow returns true even though no
* changes were needed.
*
* @param other The profile to follow
* @return True if successful, false otherwise
*/
public boolean follow(ProfileInterface other);
/**
* Removes the specified profile from this profile's following set.
*
* <p> If this profile's following set does not contain other, or if other
* is null, then unfollow returns false without modifying the profile.
* Otherwise, this profile in modified in such a way that other is removed
* from this profile's following set.
*
* @param other The profile to follow
* @return True if successful, false otherwise
*/
public boolean unfollow(ProfileInterface other);
/**
* Returns a preview of this profile's following set.
*
* <p> The howMany parameter is a maximum desired size. The returned array
* may be less than the requested size if this profile is following fewer
* than howMany other profiles. Clients of this method must be careful to
* check the size of the returned array to avoid
* ArrayIndexOutOfBoundsException.
*
* <p> Specifically, following returns an array of size min(howMany, [number
* of profiles that this profile is following]). This array is populated
* with arbitrary profiles that this profile follows.
*
* @param howMany The maximum number of profiles to return
* @return An array of size ≤howMany, containing profiles that this
* profile follows
*/
public ProfileInterface[] following(int howMany);
/**
* Recommends a profile for this profile to follow. This returns a profile
* followed by one of this profile's followed profiles. Should not recommend
* this profile to follow someone they already follow, and should not
* recommend to follow oneself.
*
* <p> For example, if this profile is Alex, and Alex follows Bart, and Bart
* follows Crissy, this method might return Crissy.
*
* @return The profile to suggest, or null if no suitable profile is found
* (only if all of this profile's followees' followees are already followed
* or this profile itself).
*/
public ProfileInterface recommend();
}
SocialClient.java
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* SocialClient is a toy application for simulating the connections between
* profiles in an asymmetric (i.e., following) social network. It is a client of
* the Set and Profile classes.
*/
public class SocialClient {
// a set to store the profiles in the system
private static SetInterface<ProfileInterface> profiles = new Set<ProfileInterface>();
// a scanner to get input from the user
private static Scanner input = new Scanner(System.in);
/**
* Runs the toy social media application.
*
* Attempts to restore data from previous runs, if possible.
*/
public static void main(String args[]) {
restore();
int selection = -1;
while (selection != 0) {
System.out.println();
System.out.println("Social Client Main Menu");
System.out.println("1. List profiles");
System.out.println("2. Create a profile");
System.out.println("3. Show a profile");
System.out.println("4. Edit a profile");
System.out.println("5. Follow");
System.out.println("6. Unfollow");
System.out.println("7. Recommend someone to follow");
System.out.println("0. Quit");
System.out.print("Selection: ");
try {
selection = input.nextInt();
} catch (NoSuchElementException e) {
selection = -1;
} catch (IllegalStateException e) {
selection = -1;
}
input.nextLine();
switch (selection) {
case 1:
list();
break;
case 2:
create();
break;
case 3:
show();
break;
case 4:
edit();
break;
case 5:
follow();
break;
case 6:
unfollow();
break;
case 7:
recommend();
break;
case 0:
save();
break;
default:
// Invalid, just ignore and let loop again
break;
}
}
}
/**
* Attempts to restore the program state from SocialClientData.bin
*/
@SuppressWarnings("unchecked")
static void restore() {
try {
ObjectInputStream restoreStream = new ObjectInputStream(new FileInputStream("SocialClientData.bin"));
profiles = (SetInterface<ProfileInterface>) restoreStream.readObject();
} catch (FileNotFoundException e) {
// File does not exist, no warning
} catch (IOException e) {
// Couldn't read file properly
System.out.println("Warning: Could not restore from existing data");
} catch (ClassNotFoundException e) {
// Couldn't cast to correct type
System.out.println("Warning: Could not restore from existing data");
}
}
/**
* Attempts to save the program state to SocialClientData.bin
*/
static void save() {
try {
ObjectOutputStream saveStream = new ObjectOutputStream(new FileOutputStream("SocialClientData.bin"));
saveStream.writeObject(profiles);
} catch (IOException e) {
// Couldn't save
System.out.println("Error: Could not save data");
e.printStackTrace();
}
}
/**
* Lists the profiles in the system for the user to choose between.
*/
public static void list() {
// Due to type erasure, toArray will return an Object[] at runtime. We
// know that all the contents are ProfileInterface type, so we can cast
// each individual entry, but we CANNOT cast the Object[] to a
// ProfileInterface[]
Object[] all = profiles.toArray();
if (all.length == 0) {
System.out.println("No profiles returned");
return;
}
int i = 1;
System.out.println();
for (Object o : all) {
ProfileInterface p = (ProfileInterface) o;
System.out.println(i++ + ". " + p.getName());
}
}
/**
* Guides the user through creating a new profile in the system.
*/
public static void create() {
System.out.print("Name: ");
String name = input.nextLine();
System.out.print("About: ");
String about = input.nextLine();
try {
profiles.add(new Profile(name, about));
} catch (SetFullException e) {
// Set should resize, should never be full
}
}
/**
* Shows the details of one profile.
*/
public static void show() {
ProfileInterface p = pick();
if (p == null)
return;
System.out.println(p.getName());
System.out.println("About: " + p.getAbout());
System.out.println("Following:");
ProfileInterface[] following = p.following(4);
for (ProfileInterface p2 : following) {
System.out.println(p2.getName());
}
}
/**
* Guides the user through picking a profile from the list.
*
* @return the profile chosen by the user
*/
public static ProfileInterface pick() {
return pick("Selection: ");
}
/**
* Guides the user through picking a profile from the list.
*
* @param theLine
* The string to display to the user as a prompt
* @return the profile chosen by the user
*/
public static ProfileInterface pick(String theLine) {
if (profiles.isEmpty()) {
System.out.println("No profiles returned");
return null;
}
System.out.println();
// Due to type erasure, toArray will return an Object[] at runtime. We
// know that all the contents are ProfileInterface type, so we can cast
// each individual entry, but we CANNOT cast the Object[] to a
// ProfileInterface[]
Object[] all = profiles.toArray();
if (all.length == 0) {
// Should have been caught by isEmpty, but just in case
System.out.println("No profiles returned");
return null;
}
int i = 1;
for (Object o : all) {
ProfileInterface p = (ProfileInterface) o;
System.out.println(i++ + ". " + p.getName());
}
System.out.print(theLine);
int selection = i;
try {
selection = input.nextInt();
} catch (NoSuchElementException e) {
// Not an int, set selection out of range
selection = i;
} catch (IllegalStateException e) {
// Should never happen
// Set selection out of range just in case
selection = i;
}
input.nextLine();
if (selection > 0 && selection < i) {
return (ProfileInterface) all[selection - 1];
} else {
return null;
}
}
/**
* Guides the user through editing a profile.
*/
public static void edit() {
ProfileInterface p = pick();
if (p == null)
return;
System.out.println(p.getName());
System.out.println("About: " + p.getAbout());
System.out.print("New About: ");
p.setAbout(input.nextLine());
}
/**
* Guides the user through adding one "following" connection (making one
* profile follow another).
*/
public static void follow() {
ProfileInterface p1 = pick("Who does the following? ");
if (p1 == null)
return;
ProfileInterface p2 = pick("Follow whom? ");
if (p2 == null || p1 == p2)
return;
p1.follow(p2);
}
/**
* Guides the user through removing one "following" connection (making one
* profile unfollow another).
*/
public static void unfollow() {
ProfileInterface p1 = pick("Who does the unfollowing? ");
if (p1 == null)
return;
ProfileInterface p2 = pick("Unfollow whom? ");
if (p2 == null || p1 == p2)
return;
p1.unfollow(p2);
}
/**
* Prompts for a profile, then recommends another profile for the chosen
* profile to follow.
*/
public static void recommend() {
ProfileInterface p1 = pick("Recommend for whom? ");
if (p1 == null)
return;
ProfileInterface p2 = p1.recommend();
if (p2 == null) {
System.out.println("No recommendation");
} else {
System.out.println("Recommend to follow " + p2.getName());
}
}
}
SetInterface.java
// There are no abstract methods to override in this interface, but declaring
// that you implement it allows objects of this type to be written out to disk
// or over the network.
import java.io.Serializable;
/**
* Set is an interface that describes the operations of the ADT set. A set is a
* homogeneous collection of objects. It is unordered, there are no limits on
* the number of items it can store, and it cannot contain duplicate items.
*/
public interface SetInterface<E> extends Serializable {
/**
* Determines the current number of entries in this set.
*
* @return The integer number of entries currently in this set
*/
public int getCurrentSize();
/**
* Determines whether this set is empty.
*
* @return true if this set is empty; false if not
*/
public boolean isEmpty();
/**
* Adds a new entry to this set, avoiding duplicates.
*
* <p> If newEntry is not null, this set does not contain newEntry, and this
* set has available capacity (if fixed), then add modifies the set so that
* it contains newEntry. All other entries remain unmodified. Duplicates are
* determined using the .equals() method.
*
* <p> If newEntry is null, then add throws IllegalArgumentException without
* modifying the set. If this set already contains newEntry, then add
* returns false without modifying the set. If this set has a capacity
* limit, and does not have available capacity, then add throws
* SetFullException without modifying the set.
*
* @param newEntry The object to be added as a new entry
* @return true if the addition is successful; false if the item already is
* in this set
* @throws SetFullException If this set has a fixed capacity and does not
* have the capacity to store an additional entry
* @throws IllegalArgumentException If newEntry is null
*/
public boolean add(E newEntry) throws SetFullException,
IllegalArgumentException;
/**
* Removes a specific entry from this set, if possible.
*
* <p> If this set contains the entry, remove will modify the set so that it
* no longer contains entry. All other entries remain unmodified.
* Identifying this entry is accomplished using the .equals() method.
*
* <p> If this set does not contain entry, remove will return false without
* modifying the set. If entry is null, then remove throws
* IllegalArgumentException without modifying the set.
*
* @param entry The entry to be removed
* @return true if the removal was successful; false if not
* @throws IllegalArgumentException If entry is null
*/
public boolean remove(E entry) throws IllegalArgumentException;
/**
* Removes an arbitrary entry from this set, if possible.
*
* <p> If this set contains at least one entry, remove will modify the set
* so that it no longer contains one of its entries. All other entries
* remain unmodified. The removed entry will be returned.
*
* <p> If this set is empty, remove will return null without modifying the
* set. Because null cannot be added, a return value of null will never
* indicate a successful removal.
*
* @return The removed entry if the removal was successful; null otherwise
*/
public E remove();
/**
* Removes all entries from this set.
*
* <p> If this set is already empty, clear will not modify the set.
* Otherwise, the set will be modified so that it contains no entries.
*/
public void clear();
/**
* Tests whether this set contains a given entry. Equality is determined
* using the .equals() method.
*
* <p> If this set contains entry, then contains returns true. Otherwise
* (including if this set is empty), contains returns false. If entry is
* null, then remove throws IllegalArgumentException. The method never
* modifies this set.
*
* @param entry The entry to locate
* @return true if this set contains entry; false if not
* @throws IllegalArgumentException If entry is null
*/
public boolean contains(E entry) throws IllegalArgumentException;
/**
* Retrieves all entries that are in this set.
*
* <p> An array is returned that contains a reference to each of the entries
* in this set. The returned array's length will be equal to the number of
* elements in this set, and thus the array will contain no null values.
*
* <p> If the implementation of set is array-backed, toArray will not return
* the private backing array. Instead, a new array will be allocated with
* the appropriate capacity.
*
* @return A newly-allocated array of all the entries in this set
*/
public E[] toArray();
}
SetFullException.java
/**
* An exception that is thrown when a set operation cannot be completed because
* the set does not have the available capacity. Should never be thrown in
* implementations that resize.
*/
public class SetFullException extends Exception {
public SetFullException() {
super();
}
public SetFullException(String e) {
super(e);
}
}
Set.java
import java.util.Arrays;
public class Set<T> implements SetInterface<T> {
private T[] set;
private int numberOfEntries;
private static final int defaultCapacity = 25;
// constructor that creates empty set of 25
public Set() {
this(defaultCapacity);
}
// constructor creates empty set of user given capacity
// modeled after the array bag constructor in Hydra lab
public Set(int givenCapacity) {
@SuppressWarnings("unchecked")
T[] tempSet = (T[]) new Object[givenCapacity];
set = tempSet;
numberOfEntries = 0;
}
@Override
// returns number of entries (aka size) of the array so that it can be used
// in the add method to check if it is full
public int getCurrentSize() {
return numberOfEntries;
}
@Override
// returns true if its empty, false if not empty
public boolean isEmpty() {
return (numberOfEntries == 0);
}
@Override
// adds and entry as well as dynamically resizes the array if full
// avoids duplicates
// if newEntry null, throws IllegalArgumentExcpetion
// if this set has reached maxCapacity, throws SetFullException
public boolean add(T newEntry) throws SetFullException, IllegalArgumentException {
boolean isFull = true;
int currentSize = getCurrentSize();
boolean place = contains(newEntry); // is true if entry is in the set
// checks if dynamic resize needed
if (currentSize >= set.length) {
capacityResize();
}
// checks for null newEntry and throws exception
if (newEntry == null) {
isFull = false;
throw new IllegalArgumentException("Entry is null.");
}
// checks for duplicate entry in the set - if duplicate doesn't add it
// and return is false
// place will equal -1 if not a duplicate in the set
else if (place == true) {
isFull = false;
}
// checks again for if set is at capacity and throws corresponding
// exception - should never happen bc of dynamic resize
// should never reach
else if (currentSize >= set.length) {
isFull = false;
throw new SetFullException();
} else {
// all conditions must be met in order to add newEntry to set
set[numberOfEntries] = newEntry;
numberOfEntries++;
}
return isFull;
}
@Override
// checks to see if entry is in set, if it is then it is removed
public boolean remove(T entry) throws IllegalArgumentException {
boolean removed = false; // true if removed, false if not
int place = getIndex(entry);
// true if entry not in set
// false if entry is in set, only will remove if this is false
if (numberOfEntries == 0) {
removed = false;
} else if (entry == null) {
removed = false;
throw new IllegalArgumentException("Entry is null.");
}
// removes entry
// place will equal -1 if not in set
else if (place >= 0 && numberOfEntries != 0) {
set[place] = set[numberOfEntries - 1]; // this replaces the entry
// you want removed, with
// the last entry
set[numberOfEntries - 1] = null; // this removes the last entry
removed = true;
}
return removed;
}
@Override
// removes an unspecified entry from the set (chose the last entry)s
public T remove() {
T otherEntry = null;
int place = numberOfEntries - 1;
if (place >= 0 && numberOfEntries != 0) {
otherEntry = set[place]; // sets the return value to the removed
// entry
set[place] = set[numberOfEntries - 1]; // this replaces the entry
// you want removed, with
// the last entry
set[numberOfEntries - 1] = null; // this removes the last entry
}
return otherEntry;
}
@Override
// removes all entries from set
public void clear() {
while (numberOfEntries != 0) {
remove();
}
}
@Override
// boolean to see if a set contains this entry
public boolean contains(T entry) throws IllegalArgumentException {
boolean isInside = false; // true if set contains this entry
int index = getIndex(entry);
if (index > -1) {
isInside = true;
}
return isInside;
}
@Override
public T[] toArray() {
@SuppressWarnings("unchecked")
T[] newArr = (T[]) new Object[numberOfEntries];
for (int index = 0; index < numberOfEntries; index++) {
newArr[index] = set[index];
}
return newArr;
}
/*
* NOT CURRENTLY USED //used in add method to check for duplicates private
* boolean checkDuplicate(T newEntry){ boolean notDuplicate = true; int
* currentSize = getCurrentSize(); // checking for duplicate entries already
* in existence, if duplicate then returns false for(int index=0;
* index<currentSize; index++){ if(newEntry.equals(set[index])){
* notDuplicate = false; } } return notDuplicate; }
*/
// used in add method to dynamically resize
private void capacityResize() {
int currentSize = getCurrentSize();
// checks to see if the current number of entries is greater or equal to
// the length of the array
// to determine if the array needs dynamically resized
if (currentSize >= set.length) {
// by convention, this will double the size/capacity of the array
// over writes current set array with new set array with double the
// capacity
set = Arrays.copyOf(set, 2 * set.length);
}
}
// used to find index where/if an entry resides
private int getIndex(T anEntry) {
// make place -1 so that if it isnt found, you get an easily recognized
// value
int place = -1, index = 0;
boolean looking = true;
while (looking && (index < numberOfEntries)) {
for (int x = 0; x < set.length; x++) {
if (anEntry.equals(set[index])) {
looking = false;
place = index;
}
}
index++;
}
return place;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.