COMP 250 Java Coding Assignment
You have just been named CEO of a chain of Cat Cafes. A cat cafe is a coffee shop in which cats are roaming and interact with customers. At the time of your promotion, you are informed that the chain does not have any repository of the cats, and maintains no information about their seniority. You are extremely upset upon hearing this as you understand those cats are your most important staff members and, like any other employees, deserve salary and working conditions that improve with seniority.
You immediately call your best friend, who recently told you they were a computer science expert. You expect them to build you a state-of-the-art database for all your cats. Upon hearing your request, they seem to hesitate a bit and, after a moment of wavering, confess that they are only taking their second computer science course and cannot yet build a professional database. However, they recently learned about binary search trees and how they can be leveraged to efficiently access data. They explain they have not yet learned about heaps and as such their idea does not utilize trees to their full potential, but it should still provide a solution to your problem. They email you a quick draft and you start getting excited about it (after all, cats do love trees), until they specify they cannot help you because they are currently busy with their new job, which they then begin describing. It sounds pretty cool until they try to convince you to invest in their ”company” by buying a bunch of knives to re-sell. You try to tell them it sounds like a pyramid scheme but they start yelling something about those only ever occurring in Ancient Egypt, and they hang up on you. You try to call them back but it appears they blocked your number.
It looks like you are going to have to build your tree on your own. You have a second look at their email to see what you have to work with, and what is left to do. COMP 250 Java Coding Assignment
The database of all cats is represented by a ternary tree CatTree. This tree has a single field root which contains a reference to the root node. The nodes are defined by a private nested class CatNode. Each CatNode is associated with data stored in a CatInfo object (code provided).
This CatInfo class stores data into the following fields:
The CatTree class contains a CatNode inner class, and a field root, which contains the root node of the tree. It also implements Iterable and includes a CatTreeIterator inner class. CatTree contains several already implemented public methods, as well as a constructor. Those methods, called on the tree, call the CatNode functions you will implement.
The CatNode inner class contains the information about the tree structure.
In addition, in the structure of the tree, CatNodes with equal seniority should be sorted in decreasing order of fur thickness.
Build your database. Note: you will be tested on time efficiency, so make sure to implements methods based on what was seen in class! COMP 250 Java Coding Assignment
[12 points] First, consider CatTree.addCat(). This method takes as input a CatInfo object, converts it to a CatNode and calls CatNode.addCat() with the CatNode as input. You are asked to implement CatNode.addCat().
Given a CatNode c and a CatNode catToAdd, c.addCat(catToAdd) adds the CatNode catToAdd in the tree with root c accordingly to the rules explained before : if the cat to be added is more senior than the cat at the root, then it has to be added to the subtree with root c.senior. In the case where the CatNode to be added has the same seniority as the root, the organization depends on fur thickness. If the cat to be added has thicker fur than the cat at the root, it should be stored in the root node, and the cat previously in the root node should be stored in the subtree with root c.same. The method should return the root of the tree it was called on.
To clarify, let us give some examples. Let us define a CatNode cA, associated with cA.data.name Alice, cA.data.monthHired equal to 87, and cA.data.furThickness equal to 50. For sim- plicity, from here on, we will refer to this as declaring a CatNode cA −→ (Alice, 87, 50). Let’s build a tree with cA at its root, which also includes cB −→ (Bob,88,60), cD −→ (Doughnut,85,50), cE −→ (Eleanor,85,45), cF −→ (Felix,85,60), and cH −→ (Hilda,95,55. COMP 250 Java Coding Assignment