Last active
August 29, 2015 14:07
-
-
Save OlgaKulikova/b70760e7584c8684b496 to your computer and use it in GitHub Desktop.
Нарисовать прямоугольник в консоли
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Figure; | |
public abstract class Figure { | |
public abstract double square(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Figure; | |
public class Rectangle extends Figure { | |
public int height, width; | |
public Rectangle(int height, int width) { | |
this.height = height; | |
this.width = width; | |
} | |
@Override | |
public double square() { | |
return height * width; | |
} | |
public void drawRectangle(char dash, char pipe, char space) { | |
char[][] rectangle = new char[height][width]; | |
for (int i = 0; i < height; i++) { | |
for (int j = 0; j < width; j++) { | |
if (i == 0 || i == (height - 1)) { | |
rectangle[i][j]= dash; | |
} else if (j == 0 || j == (width - 1)) { | |
rectangle[i][j] = pipe; | |
} else { | |
rectangle[i][j]= space; | |
} | |
} | |
} | |
for (int i = 0; i < height; i++) { | |
for (int j = 0; j < width; j++) { | |
System.out.print(rectangle[i][j]); | |
} | |
System.out.println(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.Module2.Lesson1.Lesson3; | |
// Написать программу, которая будет рисовать на консоли прямоугольник с заданными длинами сторон. | |
import Figure.Rectangle; | |
public class Task4 { | |
public static void main(String[] args) { | |
Rectangle rec = new Rectangle(5, 15); | |
char dash = '-', pipe = '|', space = ' '; | |
rec.drawRectangle(dash, pipe, space); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment