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