Question
Write two public classes (named exactly), TextBox and TextBoxTester . TextBox contains the following overloaded static methods called textBoxString . This method returns a String
Write two public classes (named exactly), TextBox and TextBoxTester. TextBox contains the following overloaded static methods called textBoxString. This method returns a String value.
- public static String textBoxString (int side)
The returned String value, when printed, displays a solid square of side characters. The character you use is up to you. Don't forget that ' ' will force a newline character into the returned String. For example, let's assume I want to use * as the character for my box:
String s = textBoxString(5);
System.out.println(s);
will print
*****
*****
***** ***** *****
- public static String textBoxString(int side, char bChar)
The returned String value, when printed, displays the outline of a square of side characters using bChar as the box character. For example,
String s = textBoxString(4, '+');
System.out.println(s);
will print
++++ + + + + ++++
- public static String textBoxString(int rows, int cols)
The returned String value, when printed, displays the outline of a rectangle of rows rows and cols columns using your default box character.
String s = textBoxString(3, 4);
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 the outline of a rectangle of rows rows and cols columns using alternating c1 and c2 characters. Note that the first printed character should be c1, and every other printed character should be c1. The second printed character should be c2, and every other printed character should be c2. For example, in the example below, the end of the first line is 'x' and the beginning of the second line is 'o'. The next printed character, at the end of the second line is 'x'.
String s = textBoxString(3, 5, 'x', 'o');
System.out.println(s);
will print
xoxox o x oxoxo
TextBoxTester has only a main method, and calls each of the textBoxString methods as a test.
Grading Elements
- All overloaded methods are implemented in TextBox
- The TextBox class has no main method
- Each method has its correct signature
- Each method returns its appropriate output
- textBoxString methods do not themselves print anything. They only return a String that, when printed by the caller, prints the correct box
- TextBoxTester has a main method and calls each TextBox.textBoxString method with appropriate parameter values
Java langage
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started