Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Could someone help me with question A,B,C and D? Java questions A. Practices suc

ID: 3823827 • Letter: C

Question

Could someone help me with question A,B,C and D? Java questions A. Practices such as the one depicted by the following program should be avoided. Assume that s desig- nates a valid instance of some stack implementation and that value is of the correct type. True or False boolean done false while done try value s pop catch (Empty StackException e) done true B. A method that throws unchecked exceptions must declare them using the keyword throws, otherwise a compile-time will be produced. True or False Good object oriented programming practices suggest that a programmer must always catch all the C. exceptions generated by the methods being called. True or False D. Consider two em BinarysearchTree objects and the method add presented in class. Adding the same elements, but in different order into the two trees, will always lead to trees of the same height True or False. E. Consider the binary search tree below.

Explanation / Answer

A) False

The given code runs fine. Following is the code which has tested given code, and its output is given below as well:

public static void main(String[] args)
{
Stack st = new Stack();
st.push(new Integer(1));
st.push(new Integer(2));
st.push(new Integer(3));
st.push(new Integer(4));
boolean done = false;
while(! done)
{
try
{
Integer a = (Integer) st.pop();
System.out.println(a);
}
catch(EmptyStackException e)
{
done = true;
}
}
System.out.println(done);

}

Output:

4
3
2
1
true

B) False

The exceptions which are not checked at compile time, are called Unchecked exceptions . If a program is throwing an unchecked exception and even if you didn’t handle/declare that exception, the program won’t give a compile-time error.

C) True

This is always a good practice to catch all the exceptions generated by the method being called.

D) False

Consider the following two input orders. The height of first tree will be 3. And the height of second tree will be 5.

order 1) 3,1,4,5,2

order 2) 1,2,3,4,5