Faculty of Engineering and Mathematical Sciences 
Not logged in (login)

help2200


This forum is provided to promote discussion amongst students enrolled in Data Structures and Algorithms (CITS2200).
 
Options:
RSS cloud
Jump to:

Lab 5 - equals(Object o)

1 of 418 articles shown, currently no other people reading this forum.
photo
From: Thomas C.
Date: Sat 4th Apr 2020, 1:33pm
Actions: 
        Login-to-reply

 

With the equals method after checking if the object o is an instance of BinaryTree I tried 
to cast o down to a BinTree object so I can call methods like getRight() or isEmpty() on it 
to compare to the given BinTree.

This works with a test class I have written and I get the correct boolean value back when 
comparing similar trees, empty trees or a tree with an object that is not a binary tree.

However when I submit the file I get a ClassCastException as seen in the image attached.

Can anyone explain how we are meant to convert Object o to something we can compare against 
the BinTree?

Any help would be greatly appreciated!

Related articles

Lab 5 - equals(Object o) (all 9) RSS
├─ THIS   Sat 4th Apr 2020, 1:33pm, Thomas C.
├─ reply 1   Sat 4th Apr 2020, 1:41pm, Thomas C.  O.P.
├─ reply 2   Tue 7th Apr 2020, 10:40am, ANONYMOUS
├─ reply 3   Tue 7th Apr 2020, 10:54am, Thomas C.  O.P.
├─ reply 4   Tue 7th Apr 2020, 11:13am, ANONYMOUS
├─ reply 5   Tue 7th Apr 2020, 12:21pm, Thomas C.  O.P.
├─ reply 6   Thu 9th Apr 2020, 12:52pm, ANONYMOUS
├─ reply 7   Thu 9th Apr 2020, 5:01pm, Thomas C.  O.P.
└─ reply 8   Thu 9th Apr 2020, 8:07pm, ANONYMOUS
This Page


Program written by: [email protected]
Feedback welcome
Last modified: 11:27am Sep 21 2020