Question
I don't know how to use startString in starPattern recursivley. For this assignments you will create an R18 project and class. The class will implement
I don't know how to use startString in starPattern recursivley.
For this assignments you will create an R18 project and class. The class will implement the following interface: IR18.java
public interface IR18 { /* Method: starString Precondition: x >= 1 (does not need to be checked) Postcondition: returns String containing x number of '*'s Requirement: starString must work recursively */ public String starString(int x); /* Method: starPattern Precondition: x >= 1 (does not need to be checked) Postcondition: prints the appropriate star pattern for the value of x Requirement: starPattern must work recursively Requirement: Uses a recursive helper method starString */ public void starPattern(int x); /* Method: palindrome Precondition: word is an instance of String Postcondition: returns true if word is a palindrome, and false otherwise Requirement: palindrome must work recursively */ public boolean palindrome(String word); }
Assignment Overview
Recursion is essentially when a method calls itself, asking for the solution of a smaller instance of the problem. Two things are vital when using recursion: a base case (or base cases) and the recursive case. First, we will be completing the code for creating a star pattern. There are two methods tha work together here. The
starString(int x)
method is a recursive method that returns a string with the appropriate number of stars to
starPattern(int x)
to be printed. EXAMPLE OUTPUT IF X == 5:
***** **** *** ** *
Next, we will implement the method
palindrome(String test)
that accepts a string and returns true or false depending on whether it is a palindrome or not. You can use any method of the String class that you think will be useful.
Both of these solutions must be recursive and cannot use loops. Think about what the base cases are and what the recursive case is.
Below is the test code for the TA to verify.
public static void main(String args[]){ R18 rec = new R18(); rec.starPattern(5); System.out.println(); System.out.println ("\'x\' is a palindrome?: " + rec.palindrome("x")); System.out.println("\'car\' is a palindrome?: " + rec.palindrome("car")); System.out.println("\'racecar\' is a palindrome?: " + rec.palindrome("racecar")); System.out.println("\'hannah\' is a palindrome?: " + rec.palindrome("hannah")); System.out.println("\'banana\' is a palindrome?: " + rec.palindrome("banana") + " ");
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started