Question: JAVA 1. Create static generic methods print and reverse that manipulate a passed array and add them to the ArrayManipulation class below. Complete the print
public class ArrayManipulation
{
public static void main(String[] args)
{
Integer[] a = { 1, 2, 3, 4, 5, 6, 7 };
Character[] b = { 'a', 'b', 'c', 'd', 'e', 'f', 'g' };
Double[] c = { 1.0, 2.0, 3.3, 4.4, 5.9, 8.7 };
print(a);
reverse(a);
print(a);
print(b);
reverse(b);
print(b);
print(c);
reverse(c);
print(c);
}
public static
{
// Fill in your code here
}
// Add a reverse method here
}
2. Build a class called LinkedListRunner with a main method that instantiates a LinkedList
aaa
bbb
ccc
ddd
eee
fff
ggg
hhh
iii
Build a ListIterator
2. Use the class below as the driver for this lab called LinkedListRunner with a main method that instantiates a LinkedList
import java.util.LinkedList;
import java.util.Stack;
public class StackRunner
{
public static void main(String[] args)
{
LinkedList
myLinkedList1.add("aaa");
myLinkedList1.add("bbb");
myLinkedList1.add("ccc");
myLinkedList1.add("ddd");
myLinkedList1.add("eee");
// print the first linked list
System.out.println("My Linked List 1:");
// your code goes here
Stack
//Iterate through elements in the linked list (don't remove them), but
// push all the elements onto the stack
// your code goes here
//Pop all the stack elements off the stack and add them to
// a new linked list
// your code goes here
//print the second linked list
System.out.println("My LinkedList 2:");
// your code goes here
}
}
How is the second list ordered compared to the first? Why?
3. Repeat Question 2, but replace the stack with a Queue. Use add() and remove() methods on the queue. Explain the ordering of elements in the second Linked list.
4. A stack is a useful tool for reversing a list of items. Pushing items onto a stack and then popping them off results in the items being returned in the reverse order from which they were pushed. Use the following class for this assignment.
public class PalindromeRunner
{
public static void main(String[] args)
{
PalindromeTester pt = new PalindromeTester();
if (pt.isPalindrome("bob"))
{
System.out.println("bob is a palindrome");
}
else
{
System.out.println("bob is not a palindrome");
}
if (pt.isPalindrome("amanaplanacanalpanama"))
{
System.out.println("is a palindrome");
}
else
{
System.out.println("amanaplanacanalpanama is not a palindrome");
}
if (pt.isPalindrome("abcdefghijklmnopqrstuvwxyz"))
}
System.out.println("abcdefghijklmnopqrstuvwxyz is a palindrome");
}
else
{
System.out.println("abcdefghijklmnopqrstuvwxyz is not a palindrome");
}
}
}
You will need to build the PalindromeTester class and provide it with a with the booleanisPalindrome(String s) method that returns true if the string s is a palindrome, otherwise it returns false. Populate the class with a Stack
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
