Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Murach's SQL Server 2012 For Developers

Authors: Bryan Syverson, Joel Murach, Mike Murach

1st Edition

1890774693, 9781890774691

More Books

Students also viewed these Databases questions

Question

Explain how you can impose your own limits on credit card spending.

Answered: 1 week ago

Question

Answered: 1 week ago

Answered: 1 week ago

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago