Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

anyone can help me with this. you need to build a class called DrawLine . The purpose of this class is create a simple mechanism

anyone can help me with this. you need to build a class called DrawLine.

The purpose of this class is create a simple mechanism to draw separation lines in a console output. the class must contain:

Two private fields

  • lineLength: the length of the line, i.e., the character count (int)
  • lineChar: the character to be replicated to create the line (char)

Three constructors

  • A default constructor; the lineLength and lineChar fields must default to 15 and '-', respectively.
  • A full constructor for lineLength and lineChar, in that order.
  • A one-parameter constructor requiring only the length of the line as argument. The character is defaulted to '-'. Constructor chaining could help you. Requirement: Any character argument is fine but, if the line length entered is 0 or less, the constructors should replace it with the value 1.

Both get methods (getLineLength and getLineChar)

Both set methods (setLineLength and setLineChar) Requirement: if the line length entered is 0 or less, the relevant set method should replace it with the value 1, just like the constructors. (Can you avoid duplication of code?)

A toString method whose output matches the following EXACTLY (with the character and the line length replaced by the appropriate values:

 DrawLine[lineChar = ~, lineLength = 25]

A draw method - The star of the show, really... The method does not take any argument and does not return anything. A call to draw() will mimic the statement

 System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~"); // using the same values as the toString above

with the character used and the length of the 'line' are specified by the class fields.

IMPORTANT Please make sure you respect the method and attribute names given above or some ot the automated tests may fail!

Example

public static void main(String[] args) { DrawLine line = new DrawLine(); line.draw(); line .setLineChar('~'); line.setLineLength(25); line.draw(); System.out.println(line); }

OUTPUT

--------------- ~~~~~~~~~~~~~~~~~~~~~~~~~ DrawLine[lineChar = ~, lineLength = 25]

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

Corporate Finance

Authors: Stephen Ross, Randolph Westerfield, Jeffrey Jaffe

10th edition

978-0077511388, 78034779, 9780077511340, 77511387, 9780078034770, 77511344, 978-0077861759

More Books

Students also viewed these Programming questions

Question

=+c) What are the factors?

Answered: 1 week ago

Question

Express the following ratios in its lowest terms.

Answered: 1 week ago

Question

Express the following ratios in its lowest terms.

Answered: 1 week ago