Question: The above answer may be correct, however, it is already a predefined class. In which, the error I get from this code is as follows:

The above answer may be correct, however, it is already a predefined class. In which, the error I get from this code is as follows:
"StaticSet.java:59: error: cannot find symbol
if (predicate.test(item)){
^
symbol: method test(T)
location: variable predicate of type Predicate
where T is a type-variable:
T extends Object declared in class StaticSet
StaticSet.java:60: error: cannot find symbol
newSet.add(item);
^
symbol: variable newSet
location: class StaticSet
where T is a type-variable:
T extends Object declared in class StaticSet
StaticSet.java:63: error: cannot find symbol
return new StaticSet>(newSet);
^
symbol: variable newSet
location: class StaticSet
where T is a type-variable:
T extends Object declared in class StaticSet
StaticSet.java:78: error: cannot find symbol
HashSet newSet = new HashSet>();
^
symbol: class r
location: class StaticSet
where T is a type-variable:
T extends Object declared in class StaticSet
StaticSet.java:80: error: cannot find symbol
newSet.add(function.apply(item));
^
symbol: variable function
location: class StaticSet
where T is a type-variable:
T extends Object declared in class StaticSet
5 errors"
Could this code fit into this? Where it says "//Your code here..." please write and explain how this could work with the code provided for StaticSet.java class:
StaticSet.java
import java.util.*;
import java.io.PrintWriter;
public class StaticSet {
private HashSet set = new HashSet();
// Constructs an empty StaticSet
public StaticSet(){
}
// Constructs the StaticSet by adding all ArrayList items
public StaticSet(ArrayList items){
for (T item : items){
set.add(item);
}
}
// Constructs the StaticSet by copying itemsToCopy's items
public StaticSet(HashSet itemsToCopy){
this.set = new HashSet(itemsToCopy);
}
public boolean contains(T item){
return true == set.contains(item);
}
public int getSize(){
return set.size();
}
public void print(PrintWriter output, String separator, String prefix, String suffix){
output.write(prefix);
boolean firstItem = true;
for (T item : set){
if (firstItem){
output.write(item.toString());
firstItem = false;
} else {
output.write(separator + item.toString());
}
}
output.write(suffix);
}
// Returns a StaticSet containing each element from this set that is not
// in otherSet.
public StaticSet difference(StaticSet otherSet){
// Your code here (remove placeholder line below)
return new StaticSet();
}
// Returns a StaticSet containing each element from this set that
// satisfies the predicate.
//- If predicate(item) returns true (1), item satisfies the predicate.
//- If predicate(item) returns false (0), item does not satisfy the predicate.
public StaticSet filter(Predicate predicate){
// Your code here (remove placeholder line below)
return new StaticSet();
}
// Returns a StaticSet containing each element from this set that is also
// in otherSet.
public StaticSet intersection(StaticSet otherSet){
// Your code here (remove placeholder line below)
return new StaticSet();
}
// Calls mapMethod(item) for each item in this set and adds the returned
// item to a StaticSet. After mapMethod has been called for each item
// in this set, the StaticSet object is returned.
public StaticSet map(Predicate mapMethod){
// Your code here (remove placeholder line below)
return new StaticSet();
}
// Returns a StaticSet containing every element from this set and every
// element from otherSet.
public StaticSet union(StaticSet otherSet){
// Your code here (remove placeholder line below)
return new StaticSet();
}
}
Thank you.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!