Question: Exercise 21 Strings By using Bluej Using the given project Strings , complete each section in the class YourCode by using the methods specified in

Exercise 21 Strings By using Bluej

Using the given project Strings, complete each section in the class YourCode by using the methods specified in each exercise (you may declare additional variables). No need to ask the user to enter values; use the variables that are already declared in the method.

The class Testing already has testing cases to test your code. You simply need to compile and execute either the main method or each section of this class.

Details about methods of the class String can be found in the String lecture slides. The method length() requires no parameters and it returns the length of the string as an int.

Folder name: A170_E21_YourLastName_YourFirstName Part A. HALF A STRING Given a string str1 of even length, print out the first half. Methods to use: substring(), length()

Testing cases:

WooHoo HelloThere abcdef ab 0123456789 kitten

Part B. WITHOUT ENDS

=> Woo => Hello => abc

=> a => 01234 => kit

Given a string str1, print out the string without the first and last char. The string length is at least 2. Methods to use: substring(), length() Testing cases:

Hello java coding code ab Chocolate! kitten woohoo

=> ell => av => odin => od => (empty string) => hocolate

=> itte => ooho

Part C. ROTATE LEFT

Given a string str1, print out a rotated left 2 version where the first 2 chars are moved to the end. The string length will be at least 2.

Methods to use: substring(), length() Testing cases:

Hello => lloHe java => vaja Hi => Hi code => deco cat => tca 12345 => 34512 Chocolate => ocolateCh bricks => icksbr

Part D. COUNT HI

Given a string, output the number of times the string hi appears anywhere in the string. Methods to use: substring(), length(), equals() Testing cases:

abc hi ho =>1 ABChi hi =>2 hihi =>2 hiHIhi =>2 h =>0 hi =>1 Hi is no HI on ahI =>0 hiho not HOHIhi =>2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!