Question
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
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