Question: you need to use the code below , to add this >>> Write a method that takes a string of characters as a parameter and

you need to use the code below , to add this >>> Write a method that takes a string of characters as a parameter and return true if the string is a palindrome and false otherwise. Your method should use a queue and stack to check the string. Test your method by reading a string from the keyboard and passing it to the method. Hint: in the method, store a copy of the string in a stack and another copy in a queue and compare.

------------------------------------------------------------------------------------------------------------

import java.util.*; public class testReverseQueue{ static Scanner console = new Scanner(System.in); public static void main(String[] args) { ArrayQueue myQueue = new ArrayQueue(100); int num; while(true){ System.out.print("Enter an integer value (999 to stop): "); num = console.nextInt(); if(num==999) break; myQueue.enqueue(num); } System.out.println("Content of myQueue befor reversing: "); System.out.println(myQueue.toString()); reverseQueue(myQueue); System.out.println("queue content after reversing:"); System.out.println(myQueue.toString()); } // End of main public static void reverseQueue(ArrayQueue Q){ int q_size; q_size=Q.size(); ArrayStack tempStack = new ArrayStack(q_size); for(int i=0; i= 0; j--) { str=str+" "+ data[j]; } return str; } }// end of ArrayStack class class ArrayQueue { // instance variables /** Default array capacity. */ public static final int CAPACITY = 1000; private int[] data; private int front = 0; // index of front private int qSize = 0; // queue size // constructors public ArrayQueue() { data = new int[CAPACITY]; } public ArrayQueue(int capacity) { data = new int[capacity]; } public int size() { return qSize; } public boolean isEmpty() { return (qSize == 0); } public void enqueue(int e) { int avail = (front + qSize) % data.length; data[avail] = e; qSize++; } public int first() { return data[front]; } public int dequeue() { int answer = data[front]; front = (front + 1) % data.length; qSize--; return answer; } public String toString() { StringBuilder sb = new StringBuilder("("); int k = front; for (int j=0; j < qSize; j++) { if (j > 0) sb.append(", "); sb.append(data[k]); k = (k + 1) % data.length; } sb.append(")"); return sb.toString(); } }// End of ArrayQueue class public class Student{ private String name; private int grade; private double cgpa; public Student (){ name=""; grade=0; cgpa=0.0; } public void setStudent(String n, int g, double c){ name = n; grade = g; cgpa = c; } public String getName(){ return name; } public int getGrade(){ return grade; } public double getCGPA(){ return cgpa; } }// End of class Student

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!