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

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 method so that it prints each item in any passed array of objects. Create a reverse method that reverses the items in any passed array. (Hint: Perform the swaps in place.) The code you write should work with the main method as it is written.

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 void print(T[] x)

{

// Fill in your code here

}

// Add a reverse method here

}

2. Build a class called LinkedListRunner with a main method that instantiates a LinkedList.Add the following strings to the linked list:

aaa

bbb

ccc

ddd

eee

fff

ggg

hhh

iii

Build a ListIterator and use it to walk sequentially through the linked list using hasNext and next, printing each string that is encountered. When you have printed all the strings in the list, use the hasPrevious and previous methods to walk backwards through the list. Along the way, examine each string and remove all the strings that begin with a vowel. When you arrive at the beginning of the list, use hasNext and next to go forward again, printing out each string that remains in the linked list.

2. Use the class below as the driver for this lab called LinkedListRunner with a main method that instantiates a LinkedList. Add the following strings to the linked list:

import java.util.LinkedList;

import java.util.Stack;

public class StackRunner

{

public static void main(String[] args)

{

LinkedList myLinkedList1 = new 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 myStack = new 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 object. Push each character of the passed string onto the stack. Java will autobox each char into a Character object.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!