Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer both parts using Java as the program. Part 2. Writing methods in Java 1. In this part, you will implement a second method

Please answer both parts using Java as the program.

image text in transcribedimage text in transcribed

Part 2. Writing methods in Java 1. In this part, you will implement a second method in the 'Lab4Part1' class. 2. Implement a method called multiconcat, that takes two input parameters where one is of type String and the other is of type int. The method returns as output a string that is equal to the input String parameter concatenated with itself n number of times (where n is the int parameter). For example, if the parameters are "hi" and 4, then the return value is "hihihihi". 3. Divide your work into step as follows: a. Write the method header. You need to answer the following questions to find out the different parts of the method header: i. What is the data type of the method output? ii. What is the method name? iii. What is the data type of the first input parameter? iv. What is the data type of the second input parameter? b. Write the method body as follows: i. Declare a local String variable that will be used to hold the output. ii. Write a for loop and the number of iterations should equal to the method's second input parameter. iii. Inside the for loop's body, append the first input parameter the output string. iv. Write a return statement to return the output string. c. Add statements in the main method to test your method as follows: i. Ask the user to enter a string and read the string. ii. Ask the use to enter the number of repetitions and read the number. iii. Call the multiconcat method with the user input as parameters. iv. Print the output of the method on the screen. Part 3. Methods and Loops 1. In this part, you are asked to change the main method of Part 2 so that the method calls the mutliConcat several times based on the user interest. 2. In order to implement this part, you need to write a while loop that is similar to the sentinel- controlled while loop that you wrote in Part 2 of Lab 2. Basically, the loop that asks the user whether she wants to run more tests and accepts the user response as "Y" or "N". If the user enters "Y", then your code asks the user to enter another String and int and uses these two inputs to call the multiConcat method

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

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions