friends! I just have one quirked up question, I seem to have an issue with my very last question in my assignment.
I'm not sure how to explain it but for some reason, while getValue() works wonderfully in my for loop, it doesn't connect with my if statement, declaring that getValue() cannot be resolved for type House. I have tried casting it over, which activates the getValue(), but then won't allow me to state ">" as an operator.
Error when casting: The operator > is undefined for the argument type(s) package.House
What my method is looking for is the price of the house sold at in the end (soldPrice in my class) and scanning through each key of the hashmap to find which key has the greatest value.
Here's the method! :)
public House maxPrice(HashMap<Integer, House> obj) {
Integer max = (Integer)obj.keySet().toArray()[0];
for(Map.Entry<Integer, House> entry : obj.entrySet()){
House currentHouse = entry.getValue();
if (currentHouse.getValue() > obj.get(max).getValue()) {
max = entry.getKey();
} return obj.get(max);
} return null;
}
For some reason, when my professor ran the same code, it worked on his compiler successfully (he had visually the same class), while mine (restarted plenty of times) doesn't. How should I overcome this?
I cannot cast the object to an int, nor an (Integer) wrapper class either.
Thanks so much for any assistance, it is all greatly appreciated!! At a complete roadblock at the moment! Let me know if you need any clarification