Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What you need to do: Write and test the following 2 overloaded methods: //precondition: ch.length() == 1 public static String setChar(String str, int index,

image text in transcribed

What you need to do: Write and test the following 2 overloaded methods: //precondition: ch.length() == 1 public static String setChar(String str, int index, String ch) public static String setChar (String str, int index, char ch) This overloaded method should return a new String containing the result when the character at position index in str has been replaced by ch. For example, the code: String word "touch"; System.out.println(word); word setChar (word, 3, "g"); System.out.println(word); word setChar (word, 0, 'r'); System.out.println(word); //calls String version //calls char version word setChar (word, 4, (char) (word.charAt (4)-3));//calls char version System.out.println(word); would output touch tough rough rouge If you know how the substring method works, you can use that. Otherwise, I would suggest calling the toCharArray() method on str to convert it to an array of char, changing the appropriate character, and then using the String constructor to convert the array back to a new String before returning it. Don't forget, it is quite legal to do one of your two methods by calling the other one.

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

Sketch the graph of the function. y = e -x/2

Answered: 1 week ago

Question

Describe the set of points defined by the equation(s). z = -3

Answered: 1 week ago