Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 as the outline of a 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(3); 
  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

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

Essential Data Protection For Estate Agencies In Singapore 2024

Authors: Yang Yen Thaw Yt

1st Edition

B0CQK79WD3, 979-8872095392

More Books

Students also viewed these Databases questions

Question

1.Which are projected Teaching aids in advance learning system?

Answered: 1 week ago

Question

6. How do histories influence the process of identity formation?

Answered: 1 week ago