Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Text Boxes (JAVA beginner) Create a class named TextBoxes. At the top declare a

ID: 3873151 • Letter: T

Question

Text Boxes (JAVA beginner)

Create a class named TextBoxes. At the top declare a char constant named DEFAULT_CH whose value is ‘*’.

Next will be main() which prompts the user to enter values for the following variables:

int sideInput

int colsInput

char c1Input

char c2Input

main() will call each of the following overloaded methods named textBoxString() and then display the results of that call. For the following, assume the user input the following values: sideInput = 3, colsInput = 4, c1Input = '+', and c2Input = 'x'.

public static String textBoxString (int side)

The returned String value, when printed, displays as a square of side characters. The character used is DEFAULT_CH. For example:

    String s = textBoxString(sideInput);

    System.out.println(s);
        

will print

***

***

***

public static String textBoxString(int side, char c1)

The returned String value, when printed, displays as a square of side characters. The character used is c1. For example:

   String s = textBoxString(sideInput, c1Input);

   System.out.println(s);
         
                

will print

++++
++++
++++
++++

public static String textBoxString(int rows, int cols)

The returned String value, when printed, displays as a rectangle of rows rows and cols columns using DEFAULT_CH character. For example:

String s = textBoxString(sideInput, colsInput);

System.out.println(s);
                

will print

****
****
****

public static String textBoxString(int rows, int cols, char c1, char c2)

The returned String value, when printed, displays a rectangle of rows rows and cols columns using alternating c1 and c2 characters. For example:

String s = textBoxString(sideInput, colsInput, c1Input, c2Input);

System.out.println(s);
         
                

will print

+x+x+
x+x+x
+x+x+

Explanation / Answer

TextBoxes.java

import java.util.Scanner;

public class TextBoxes {

static char DEFAULT_CH = '*';

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.println("Enter the side: ");

int sideInput = scan.nextInt();

System.out.println("Enter the columns: ");

int colsInput = scan.nextInt();

System.out.println("Enter the c1 input: ");

char c1Input = scan.next().charAt(0);

System.out.println("Enter the c2 input: ");

char c2Input = scan.next().charAt(0);

String s = textBoxString(sideInput);

System.out.println(s);

s = textBoxString(sideInput, c1Input);

System.out.println(s);

s = textBoxString(sideInput, colsInput);

System.out.println(s);

s = textBoxString(sideInput, colsInput, c1Input, c2Input);

System.out.println(s);

}

public static String textBoxString(int side) {

String s = "";

for (int i = 0; i < side; i++) {

for (int j = 0; j < side; j++) {

s = s + DEFAULT_CH;

}

s = s + " ";

}

return s;

}

public static String textBoxString(int side, char c1) {

String s = "";

for (int i = 0; i < side; i++) {

for (int j = 0; j < side; j++) {

s = s + c1;

}

s = s + " ";

}

return s;

}

public static String textBoxString(int rows, int cols) {

String s = "";

for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++) {

s = s + DEFAULT_CH;

}

s = s + " ";

}

return s;

}

public static String textBoxString(int rows, int cols, char c1, char c2) {

String s = "";

for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++) {

if((i+j)%2==0)

s = s + c1;

else

s = s + c2;

}

s = s + " ";

}

return s;

}

}

Output:

Enter the side:
3
Enter the columns:
4
Enter the c1 input:
+
Enter the c2 input:
x
***
***
***

+++
+++
+++

****
****
****

+x+x
x+x+
+x+x

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote