Question

In: Computer Science

java from control structures through objects 6th edition, programming challenge 5 on chapter 16 Write a...

java from control structures through objects 6th edition, programming challenge 5 on chapter 16

Write a boolean method that uses recursion to determine whether a string argument is a palindrome. the method should return true if the argument reads the same forward amd backword. Demonstrate the method in a program, use comments in the code for better understanding. there must be a demo class and method class

also ..

generate javadocs through eclipse compiler. And

make a UML diagram with 3 rows and 1 column

like this bellow.... use (-) for private and (+) for public in the diagram

class name
attributes
operations

here is another example of how the UML diagram should look

https://d2slcw3kip6qmk.cloudfront.net/marketing/pages/chart/uml/class-diagram/class-diagram-object-334x224.PNG

Solutions

Expert Solution

Palindrome class UML diagram :

Java Code:

/**
*
* This class contain a boolean method that uses recursion to determine whether
* a string argument is a palindrome. the method should return true if the
* argument reads the same forward amd backword
*
*/
public class Palindrome {
  
   private String inputString;
  
   /**
   * Field constructor
   * @param inputString
   */
   public Palindrome(String inputString) {
       this.inputString = inputString;
   }
  

   /**
   * @return the inputString
   */
   public String getInputString() {
       return inputString;
   }

   /**
   * @param inputString the inputString to set
   */
   public void setInputString(String inputString) {
       this.inputString = inputString;
   }
   /**
   * This method is accessible to public determine whether
   * input String is a palindrome
   * @return
   */
   public boolean isPalindrome(){
       return isPalindromeRecursion(this.inputString);
   }

   /**
   * This method determine whether input String is a palindrome using
   * recursion.
   *
   * @param inputString
   * @return true if inputString is palindrome.
   *
   */
   private boolean isPalindromeRecursion(String inputString) {
       // Check for empty or single character string & it must be a palindrome
       if (inputString.length() == 0 || inputString.length() == 1) {
           return true;
       }
       // Check for recursive call to determine whether input String is a
       // palindrome
       if (inputString.charAt(0) == inputString.charAt(inputString.length() - 1)) {
           return isPalindromeRecursion(inputString.substring(1, inputString.length() - 1));
       }

       return false;
   }

}

/**
* The Palindrome Driver Class
*
*/
public class PalindromeDriver {

   /**
   * Class driver main method
   *
   * @param args
   */
   public static void main(String[] args) {
       Palindrome palindrome = new Palindrome("ABC");
       System.out.println(palindrome.getInputString()+":"+palindrome.isPalindrome());
       palindrome.setInputString("ABA");
       System.out.println(palindrome.getInputString() + ":" + palindrome.isPalindrome());
       palindrome.setInputString("ABAC");
       System.out.println(palindrome.getInputString() + ":" + palindrome.isPalindrome());
       palindrome.setInputString("ABAG");
       System.out.println(palindrome.getInputString() + ":" + palindrome.isPalindrome());
       palindrome.setInputString("");
       System.out.println(palindrome.getInputString() + ":" + palindrome.isPalindrome());
       palindrome.setInputString("B");
       System.out.println(palindrome.getInputString() + ":" + palindrome.isPalindrome());
   }

}

Javadoc:


Related Solutions

JAVA CODE --- from the book, java programming (7th edition) chapter 7 carly's question I am...
JAVA CODE --- from the book, java programming (7th edition) chapter 7 carly's question I am getting a illegal expression error and don't know how to fix it, also may be a few other error please help CODE BELOW import java.util.Scanner; public class Event { public static double pricePerGuestHigh = 35.00; public static double pricePerGuestLow = 32.00; public static final int LARGE_EVENT_MAX = 50; public String phnum=""; public String eventNumber=""; private int guests; private double pricePerEvent; public void setPhoneNumber() {...
Starting Out with Java (6th Edition) chapter 8, 3PC Requirement: Each of the RoomCarpet and RoomDimension...
Starting Out with Java (6th Edition) chapter 8, 3PC Requirement: Each of the RoomCarpet and RoomDimension classes should have a toString method, an equals method, a copy method, and a copy constructor. The RoomCarpet class should have mutators and accessors for both of its fields.
In Programming Challenge 12 of Chapter 3, you were asked to write a program that converts...
In Programming Challenge 12 of Chapter 3, you were asked to write a program that converts a Celsius temperature to Fahrenheit. Modify that program so it uses a loop to display a table of the Celsius temperatures 0–20, and their Fahrenheit equivalents. Display table on screen and it a .txt file. c++
Write a java application that implements ArrayStack in chapter 16 of your textbook.
Write a java application that implements ArrayStack in chapter 16 of your textbook. Your application should have two files: 1. ArrayStack.java: This file will have the implementation of your stack. 2. TestStack.java: This file will have the main method where you declare your stack object and test the different stack operations. In addition to the ArrayStack methods given in the book, you are to write a toString method. This will allow you to print the Stack object from main. You...
Java Programming 5th edition Chapter 10 Inheritance Programs Part 1 Number 3 on page 719 which...
Java Programming 5th edition Chapter 10 Inheritance Programs Part 1 Number 3 on page 719 which creates a Point class with 2 instance variables; the xCoordinate and yCoordinate. It should have a default constructor and a values constructor. Also include a set method that sets both attributes, a get method for each attribute, and a method that redefines toString() to print the attributes as follows. point: (x, y) Part 2 Do number 4 on page 719 which creates a Circle...
Object-Oriented Design and Patterns in Java (the 3rd Edition Chapter 5) - Create a directory named...
Object-Oriented Design and Patterns in Java (the 3rd Edition Chapter 5) - Create a directory named as the question number and save the required solutions in the directory. - Each problem comes with an expected tester name. In the directory for a given problem, including the tester and all java classes successfully run this tester. Exercise 5.2 ObserverTester.java - Improve Exercise 1 by making the graph view editable. Attach a mouse listener to the panel that paints the graph. When...
Write a java program that creates a hashtable with 10 objects and 5 data members using...
Write a java program that creates a hashtable with 10 objects and 5 data members using mutator and accessor methods for each data member.
Program: Java Write a Java program using good programming principles that will aggregate the values from...
Program: Java Write a Java program using good programming principles that will aggregate the values from several input files to calculate relevant percentages and write the values to an output file. You have been tasked with reading in values from multiple files that contains different pieces of information by semester. The Department of Education (DOE) would like the aggregate values of performance and demographic information by academic year. A school year begins at the fall semester and concludes at the...
Program: Java Write a Java program using good programming principles that will aggregate the values from...
Program: Java Write a Java program using good programming principles that will aggregate the values from several input files to calculate relevant percentages and write the values to an output file. You have been tasked with reading in values from multiple files that contains different pieces of information by semester.    The Department of Education (DOE) would like the aggregate values of performance and demographic information by academic year. A school year begins at the fall semester and concludes at the...
Java Programming: spellcheck Write code to read in a dictionary from the current directory called "dict.txt"...
Java Programming: spellcheck Write code to read in a dictionary from the current directory called "dict.txt" (you can find this in the current directory/data) Add each word to a hash map after splitting words and throwing away punctuation (see the demo). open a file called "spell.txt" to check in the current directory. Print out every word in spell.txt that is NOT in the dictionary. Example: if spell.txt contains: hello, this is a test. 2152189u5 Misspelled! cApitalized The output should be:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT