A mobile consists of 2 branches, a left branch and a right branch.
Each branch has a length. From the end of a branch hangs either a weight or another mobile.
picture of a mobile
a. Which object classes do you see in the above description? Use the heuristic 'an object is described by a noun' to make a good choice. Do not choose too few classes, do not choose too many. What are the properties of each of your classes? After answering all these questions, you should be able to write your classes in Java - at this point they do not have any methods, though. Make sure you have the right constructors that allow you to describe mobiles like the one displayed above, using concrete double numbers for all the lengths and weights and with arbitrary combinations of sub-mobiles!
b. Write an instance method double totalWeight() that returns the total weight of a mobile.
c. A mobile is balanced if the torque applied by its top-left branch is equal to the torque applied by its top-right branch and all sub-mobiles are also balanced. Torque is defined as the product of the length of a branch and its total weight hanging off the end of the branch.
Write a method boolean isBalanced() that tests whether a mobile is balanced.
Keep Up with TechRepublic