Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java exercise a) Write a method called makeLine that takes one integer and two char parameters (element and separator) and returns a String. The method

Java exercise

a) Write a method called makeLine that takes one integer and two char parameters (element and separator) and returns a String. The method should return a String representing a single line that is formed from the two characters given as parameters. Your method should construct this line by using the element character alternating with the separator character. The integer parameter gives the number of element characters there should be in the String, and these should each be separated by one separator character. Additionally, there should be one separator character at the start and end of the line, and the whole String should have an end-line character at the end.

For example, if your method were called with integer parameter 3 and char parameters A and b respectively, then the returned String would look like this: bAbAbAb

b) Write a method called makeGrid that takes one integer as a parameter and returns a String. The method should return a String representing a grid of squares, made up of (hyphen), | (vertical line), and space characters. Your method should use the result of part (a) to generate a square grid using the integer parameter as the size. The grid should look like an array of squares, like on a checkerboard. For example, if called with the parameter 3, then the returned String would look like this: - - -

| | | |

- - -

| | | |

- - -

| | | |

- - -

c) Write a main method prints to output a prompt for the user that asks for a single integer value, then use either the Scanner class or showInputDialog method to accept a single integer value as input. Use the method from part (b) to print to output a square grid of the appropriate size.

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

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

13.1 Explain the strategic role of employee benefits.

Answered: 1 week ago

Question

Recognize the four core purposes service environments fulfill.

Answered: 1 week ago