anyone can help me with this. you need to build a class called DrawLine . The purpose
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 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]
Corporate Finance
ISBN: 978-0077861759
10th edition
Authors: Stephen Ross, Randolph Westerfield, Jeffrey Jaffe