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

i need help with this plz .. Write a program in java that will accept a string f

ID: 644424 • Letter: I

Question

i need help with this plz ..

Write a program in java that will accept a string from user. You program will then check if the string entered is mirror-word. Mirror-word is a word that spells the same either from left or from right.

Eg. RADAR is a mirror-word. SAlMA is not a mirror-word.

You need to implement using a queue and an array, as in the followings description. (You may use the same class of Stack from textbook)

Continuously get input from user until user wanted to stop.

For every input given by user, enque (insert) each character into a queue and the array.

Then repeatedly deque a char from queue and read a char from the array, compare both chars. If the chars are not the same, add a counter.

If the counter remains 0, it shows that the word is mirror-word.

Explanation / Answer

Java Program for Mirror words:

import java.util.Scanner;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
import java.io.*;
public class Mirrorword
{
public static void main(String[] args) throws IOException
{
Scanner stdin = new Scanner(System.in);
//Scanner stdin = new Scanner(new File("input.txt"));
String line;
  
do
{
System.out.print("Your expression (or return to end): ");
   line = stdin.nextLine();
   if (is_ Mirror word(line))
   System.out.println("This is a Mirror word");
   //JOptionPane.showMessageDialog(frame, "This is a Mirror word");
   else
   //JOptionPane.showMessageDialog(frame, "This is NOT a Mirror word ");
   System.out.println("This is NOT a Mirror word ");
}
while (line.length() != 0);
}

public static boolean is_ Mirror word (String input)
{
Queue<Character> q = new LinkedList<Character>();
Stack<Character> s = new Stack<Character>();
Character letter;
int mismatches = 0;
  
for (int i = 0; i < input.length(); i++)
{
letter = input.charAt(i);
   if (Character.isLetter(letter))
   {
   q.add(letter);
   s.push(letter);
   }
}
while (!q.isEmpty())
{
if (q.remove() != s.pop())
   mismatches++;
}
return (mismatches == 0);
}
}