I created a HashSet of Console objects which use 2 strings. One is for the company name for the console, the other is the console name. I have no issues with most of the basic methods (I know how to add to a HashSet, clear a HashSet etc...), but I am having issues with removing a single object, and with checking if the HashSet contains a certain object. I have included the relevant pieces of code for the HashSet class
import java.util.HashSet;
public class testHashSet
{
private HashSet <Console> testSet;
/**
* Constructor
*/
public testHashSet()
{
testSet = new HashSet <Console> () ;
setTestSet();
}
public void setTestSet(){
testSet.add(new Console("Nintendo" , "Wii U"));
testSet.add(new Console("Sony" , "PS4"));
testSet.add(new Console("XBox" , "Microsoft"));
}
/**
* Method to remove object from HashSet
*/
public void removeData(){
Console d = new Console("Sony" , "PS4");
testSet.remove(d);
printHashSet();
}
/**
* Method to check for specific object in HashSet
*/
public void checkForItem(String anyCompany, String anyConsole){
boolean exist = testSet.contains(new Console (anyCompany, anyConsole));
System.out.println(exist);
}
Edit: Here is the source code for the Console class:
public class Console
{
private String companyName;
private String consoleName;
/**
* Constructor for objects of class Console
*/
public Console(String anyCompany, String anyConsole)
{
companyName = companyName;
consoleName = anyConsole;
}
public void printConsoleInfo(){
System.out.println(consoleName + " is a " + companyName + " console.");
}
}