Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

ID: 3879027 • Letter: J

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);

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$

Explanation / Answer

here is your modified Function : ---------------------->>>>>>>>>>>..

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)+1);

this.setSymbol('|');

this.draw(1);

this.newline();

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote