Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java question Include all of the following work in a single class named Question1. Use appropriate comments for all custom methods. It is your responsibility

Java question

Include all of the following work in a single class named Question1. Use appropriate comments for all custom methods. It is your responsibility to ensure your code compiles before you submit! Write several methods that deal with Strings. Be aware of whether each method is asking you to take input from parameters or take input from the user (using the Scanner class).

a)Write a method called shiftString that shifts a certain number of characters from the end of a String to the front. Your method should take a String and an integer as parameters. The String parameter is the String to be used, and the integer is the number of characters to shift from the end to the beginning of the String. Your method should return a String that corresponds to the parameter String after the appropriate number of characters on the end have been shifted to the beginning, in the same order they originally appeared.

For example, the return value after calling this method with parameters Java and 2 should be vaJa. The return value after calling this method with parameters Winston and 4 should be stonWin.

b)Write a method called allShifts that calculates all of the possible back-to-front character shifts for a given String. Your method should take a single String as a parameter and return a String that represents all of the possible shifts of characters (from the end to the front), starting with the original String, and with each shift being represented on a separate line. Your method should not print any output of its own.

For instance, the return value after calling this method with parameter Java should be:

Java

aJav

vaJa

avaJ

and after calling with parameter Nepal should be:

Nepal

lNepa

alNepa

palNe

epalN

c)Write a method called isPalindrome that determines whether a String value is the same backwards as forwards. Your method should take one String parameter that is the String value to be checked. Your method should return true only if the String parameter consists of the same sequence of characters back to front as it does front to back (ignoring case, in both instances). Otherwise, it should return false.

For example, the return value after calling this method with parameter Brightspace should be false, and the return value after calling this method with parameter avid DiVA should be true.

d)Write a method called checkForPalindrome that determines whether a String given as input by the user is a palindrome. Your method should not take any parameters, but should use the Scanner class to take input from the user when the method is called. Give the user a meaningful prompt for their input. Your method should return true if the user-inputted String was a palindrome (ignoring case), and false otherwise.

For example, the return value after the user inputs hello should be false, and the return value after the user inputs Anna should be true.

e)Write a method called flip that reverses the order of the characters in a String. Your method should take a single String as a parameter and return a String that corresponds to the parameter String when written in reverse order.

For example, the return value after calling this method with parameter Winston should be notsniW.

f)Write a method called mirror that creates a palindrome from a String given as input by the user. Your method should not take any parameters, but should use the Scanner class to take input from the user when the method is called. Give the user a meaningful prompt for their input. Your method should process the String given as input, as return a String that is mirrored around the last letter of the input.

For example, the return value after the user inputs hello should be hellolleh, and the return value after the user inputs Java should be JavavaJ.

g)Write a main method that calls the methods from parts (b), (d), and (f) at least once each and prints out a meaningful message for each of their outputs. As an example of a meaningful message, your output could look like this after calling the method from part (d):

The input Ana is a palindrome: true

Verify that your methods behave as you expect; however, you do not need to submit any output for your program.

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions

Question

differentiate the function ( x + 1 ) / ( x ^ 3 + x - 6 )

Answered: 1 week ago

Question

13-4 What are alternative methods for building information systems?

Answered: 1 week ago