Guys I have a task in java programming I need your help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 2

Guys I have a task in java programming I need your help

Q 1. Write java code for a class called StackOfPalindromes, which is used to check an array of words, determine the palindromes among these words, and save the palindromes in a stack. The class contains: 1-A String array named words for the words to be checked. 2-An integer data field named size for the stack’s size. 3-An integer constant DEFAULT_CAPACITY for the stack’s default capacity, which is 5. 4A no-arg constructor that invokes an arg-constructor, which creates a stack with the specified capacity. 5A method named push() that takes a word, filters it from any non-alphabetic characters (i.e. remove numbers and other symbols), checks if it is a palindrome, and pushes it to the stack only if its palindrome. 6A method named pop() that returns the word on top of the stack and removes it from the stack. Q 2. Draw the UML diagram for the class StackOfPalindrmes. Q 3. Write a test class: TestStackOfPalindromes that: Create a StackOfPalindromes object using the class’s no-arg constructor. Use this object to push

25th Feb 2021, 9:18 AM
x _6rd
x _6rd - avatar
7 Answers
+ 2
Hi! What kind of help you need?
25th Feb 2021, 9:31 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
I try to do the code and I most finished but when I tried it doesn't work there is some mistakes , I will send the code here and I hope you help me .
25th Feb 2021, 9:35 AM
x _6rd
x _6rd - avatar
+ 1
Please, for better help, put this code on codes playground ("codes" section { }), make it public and paste link here
25th Feb 2021, 9:42 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Ok I got it
25th Feb 2021, 9:43 AM
x _6rd
x _6rd - avatar
0
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package pakcageofhw; public class StackOfPalindromes { String [] words; int size; public static final int DEFAULT_CAPACITY = 5; public StackOfPalindromes(){ this(DEFAULT_CAPACITY); } public StackOfPalindromes(int capacity){ words = new String[capacity]; } public void push(String value){ StringBuilder sb = new StringBuilder(); for (int i = 0; i < value.length(); i++) { if (Character.isLetterOrDigit(value.charAt(i))) { sb.append(value.charAt(i)); } } words[size] = value; } public String pop(){ if(size==0) return "Stack is empty"; return words[--size]; } }
25th Feb 2021, 9:39 AM
x _6rd
x _6rd - avatar
0
This is my class and when I invoke it from main method it doesn't work
25th Feb 2021, 9:40 AM
x _6rd
x _6rd - avatar