Question: Looking for this in Java please. Section 1: 1. Add your section comment to the code. 2. Utilize a try/catch block where needed. 3. Define
Looking for this in Java please.
Section 1:
1. Add your section comment to the code.
2. Utilize a try/catch block where needed.
3. Define an array called mammals that contains 6 strings.
4. Load the array with the following 6 strings, Bear, Gorilla, Tiger, Polar Bear, Lion, and Monkey. Precision is important in software development, so be sure to use the correct spelling and case for each string.
5. Implement a set called setMammals and populate the set from the array called mammals.
a. In Java, use the HashSet class.
b. In C#, use the HashSet class.
c. In PHP, utilize the class SplObjectStorage (found at The SplObjectStorage class page in the PHP manual).
6. Print *********** Section: 1 *********** to the console.
7. On a new line, print Contents of the set are:
8. On a new line, print a list of every element in the set.
9. Create a new set called sortedMammals derived from the setMammals set.
a. In Java, use the TreeSet class.
b. In C#, use the SortedSet class.
10. On a new line, print Contents of the sorted set are:
11. On a new line, print a list of every element in the sorted set.
12. On a new line, print The first item in the set is: followed by the first item in the sorted set.
13. On a new line, print The last item in the set is: followed by the last item in the sorted set
Section 2:
Add your section comment to the code.
Utilize a try/catch block where needed.
Implement a new linked list called myFriends.
Add the following friends names and phone numbers to myFriends.
Fred 602-299-3300"
Ann 602-555-4949"
"Grace 520-544-9898"
"Sam 602-343-8723"
"Dorothy 520-689-9745"
"Susan 520-981-8745"
"Bill 520-456-9823"
"Mary 520-788-3457"
Print a blank line.
On a new line, print *********** Section: 2 *********** to the console.
Print a blank line.
On a new line, print The contents of my friends list:
Print the list of items from the linked list with each friend on a new line.
Remove Bill from the list.
Remove the first and last elements from the list.
Add code that changes Marys phone number to 520-897-4567.
Print a blank line.
On a new line, print The updated contents of my friends list:
Print the list of items from the linked list with each friend on a new line.
On a new line print The number of friends in my list is: followed by the number of items in the list.
Add code to check if Fred is still in the list and on a new line, print a statement as to whether or not Fred is still present in the list.
Language-Specific Hints
JAVA Use LinkedList class and methods add(), removeFirst(), removeLast(), remove(), set(), size()
C# use LinkedList class and methods and properties AddFirst(), AddLast(), RemoveFirst() RemoveLast(), Count
PHP use SplDoublyLinkedList class and methods push(), pop(), offsetUnset(), offsetSet(), count()
Section 3:
Note: In Part A, Section 3, you were provided code to create a binary tree. Copy that code into this section of Part B and then add the following.
1. Add your section comment to the code, at the beginning of this section of code.
2. Utilize a try/catch block where needed.
3. Write a method called printInOrder() which traverses the binary tree in order, printing the values along the way.
4. Write a method called printPreOrder() which traverses the binary tree in order, printing the values along the way.
5. Write a method called printPostOrder() which traverses the binary tree in order, printing the values along the way.
6. Write a method called traverse() which will do the following.
a. Print a blank line.
b. On a new line print ********** Section 3 **********
c. Print a blank line.
d. On a new line print Traversing the binary tree in order:
e. Call the printInOrder() method, passing it the root node.
f. On a new line print Traversing the binary tree in pre-order:
g. Call the print PreOrder() method, passing it the root node.
h. On a new line print Traversing the binary tree in post-order:
i. Call the print PostOrder() method, passing it the root node.
Hint: There are always 3 steps to a traversal of a binary tree.
a. Visit the current node
b. Traverse its left subtree
c. Traverse its right subtree
The order in which you perform these 3 steps
results in the different traversal orders:
Pre-order traversal: (1) (2) (3)
In-order traversal: (2) (1) (3)
Post-order traversal: (2) (3) (1)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
