Question: Java (Atom editor) question. Introduction to Computing and Programming This is the code for the method... public void drawCenteredLine(int length, char symbolToUse) { this.setSymbol('|'); this.draw(1);

Java (Atom editor) question. Introduction to Computing and Programming

Java (Atom editor) question. Introduction to Computing and Programming This is the

This is the code for the method...

public void drawCenteredLine(int length, char symbolToUse)

{

this.setSymbol('|');

this.draw(1);

this.makeSpace((40-length)/2);

this.setSymbol(symbolToUse);

this.draw(length);

this.makeSpace((40-length)/2);

this.setSymbol('|');

this.draw(1);

this.newline();

}

When I enter an odd number into the method, there isn't a space to the right. (It needs to be a total of 40 characters.) I think I need to change something in the second " this.makeSpace((40-length)/2); "

The assignment says:

If the number passed in to the method is odd, it should print one more symbol before the middle than after the middle. E.g.

jose.drawCenteredLine(15, $);

should print

| $$$$$$$$$$$$$$$ |

Note that the line above is the | symbol, followed by 12 spaces, followed by 15 $s, followed by 13 spaces followed by the | symbol, followed by a newline (i.e. there is one more $ on the left than there is on the right).

Important notes:

You can assume that the integer passed in to drawCenteredLine will never be greater than 40, but may be 0 or 40 or anything in between.

Note that the line printed should end with a newline.

You MUST use the ASCIITurtle methods ONLY to draw this line. You may NOT include any called to System.out.println directly in your method.

[cs8aw] Cs8awapkitscseb240-08.ucsd.edu:/home/linux/ieng6/cs8aw/cs8awapk/psa2-x File Edit View Search Terminal Help Tue Jan 23, 2018 9:29pm Prepping cs8aw [cs8awapk@its.cseb240-98]~295$ cd psa2 [cs8awapk@its-cseb240-08] :psa2:206$ java DrawCenteredLineTest [cs8awapk@its-cseb240-08]:psa2:207$ C [Cs8awapk@its-cseb240-08]:psa2:207$ javac Create CreatePyramid.class CreateShapes.class CreatePyramid.java CreateShapes.java [cs8awapk@its-cseb240-08]:psa2:207$ javac CreatePyramid.java [cs8awapk@its-cseb240-08] :psa2:208$ java CreatePyramid [cs8awapk@its-cseb240-08]:psa2:209$

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!