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

Which are the three control structures used in java programming. Which of these three control structures...
Which are the three control structures used in java programming. Which of these three control structures is used in every program or application
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.
1. Chapter 5, Programming Challenge #8, Conversion Program (page 314). Program Name: FinalExamConversion. Write a program...
1. Chapter 5, Programming Challenge #8, Conversion Program (page 314). Program Name: FinalExamConversion. Write a program that asks the user to enter a distance in meters. The program will then present the following menu of selection: 1. Convert to Kilometers 2. Convert to Inches 3. Convert to Feet 4. Quit the Program The program will convert the distance to kilometers, inches or feet, depending on the user’s selection. Write the following methods: • getInput: This method prompts user to enter...
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...
java please Write a program that creates an ArrayList and adds 5 circle objects to the...
java please Write a program that creates an ArrayList and adds 5 circle objects to the list , and display all elements in the list by invoking the object’s toString() method.
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT