DrawArc(left, top, width, height, angle1, angle2)angle1 and angle2 denote the beginning and ending angle of the arc. An oval can be created by setting angle1 to 0 and angle2 to 360. A circle can be similarly created, except that in addition the width must equal the height.
The format of this command could lead you to define a class hierarchy in which an oval is a subclass of an arc, and a circle is a subclass of an oval:
arc | oval | circle
The oval subclass does not want to provide either the SetAngle1 or SetAngle2 methods because it is a closed arc. The circle subclass additionally wants to eliminate the setWidth and setHeight methods and add a setDiameter method. Answer the following questions:
package LinkedList; class ListNode { protected int value; String name; } package LinkedList; public class List { ListNode header; protected ListNode sentinelNode; public List() { header = new ListNode(); 1) header.value = 10; 2) header.name = "brad"; sentinelNode = new ListNode(); } } package LinkedQueue; class Queue extends LinkedList.List { public Queue() { 3) header.value = 20; 4) sentinelNode.value = 30; } }Answer the following yes/no questions about the above code and for each answer explain why you answered as you did:
>>> + 3 6 9.00 >>> / 2 3 0.67 >>> * 8 3 24.00 >>> Ctrl-D
Your program should read in one expression at a time, build an expression tree for each expression, and then evaluate the expression tree and print out the answer.
For example, given the expression:
* 2 3your program should construct the expression tree:
* / \ 2 3Each of your nodes should be an object that is an instance of some class. I know that you can solve this problem much more easily by simply looking at the first character in the input string and then performing the appropriate operation on the next two numbers. You will receive a 0 if you try to do it this way. The point of this problem is to get you started doing object-oriented design on a simple problem that you can easily solve. By giving you an easy problem, I am allowing you to focus on how to do the object-oriented design, rather than how to solve the problem.
A good inheritance hierarchy for this program would be:
TreeNode | ----------------- | | OperatorNode NumberNode | ---------------------------------- | | | | PlusNode MinusNode MultiplyNode DivideNodeThe actual expression tree from above would then look like:
MultiplyNode | ---------------------- | | NumberNode NumberNodePart of this assignment involves figuring out what methods to define and where to place them, and figuring out which classes should be abstract and which should be concrete.
Place all of your classes in a package named formula. The class containing the main method should be named ExpressionTree.
Your program may assume that the input is always correct and has the correct number of operands (my executable catches errors but yours does not need to).
java -jar /home/bvz/cs365/hw/hw2/ExpressionTree.jar
Extend your interpreter so that it can handle recursive prefix expressions. For example:
>>> * 3 / 20 5 12.0 >>> / 2 + -3 6 0.67 >>> + + / 24 * 2 4 - 3 5 6 7.00