Skip to content

Commit 2cdfece

Browse files
authored
Blessed he that readeth, &they that hear the words
Blessed [is] he that readeth, and they that hear the words of this prophecy, and keep those things which are written therein: for the time [is] at hand. (Revelation 1:2)
1 parent 67d0317 commit 2cdfece

1 file changed

Lines changed: 104 additions & 0 deletions

File tree

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
2+
//Blessed [is] he that readeth, and they that hear the words of this prophecy, and keep those things which are written therein:
3+
//for the time [is] at hand. (Revelation 1:2)
4+
5+
package com.javarush.task.task25.task2515;
6+
7+
public class Canvas {
8+
9+
private int width, height;
10+
private char[][] matrix;
11+
12+
public Canvas(int width, int height) {
13+
this.width = width;
14+
this.height = height;
15+
this.matrix = new char[height][width];
16+
}
17+
18+
public void clear() {
19+
//drawMatrix(0,0,new int[width][height],' ');
20+
for (int i = 0; i < height; i++) {
21+
for (int j = 0; j < width ; j++) {
22+
matrix[i][j] = ' ';
23+
}
24+
System.out.println();
25+
}
26+
System.out.println();
27+
}
28+
29+
public void print() {
30+
for (int i = 0; i < height; i++) {
31+
for (int j = 0; j < width ; j++) {
32+
System.out.print(matrix[i][j]);
33+
}
34+
System.out.println();
35+
}
36+
System.out.println();
37+
}
38+
39+
public void setPoint(double x, double y, char c) {
40+
int xRnd = (int) Math.round(x);
41+
int yRnd = (int) Math.round(y);
42+
if (xRnd >= 0 && xRnd < matrix[0].length && yRnd >= 0 && yRnd < matrix.length) {
43+
matrix[yRnd][xRnd] = c;
44+
}
45+
}
46+
47+
public void drawMatrix(double x, double y, int[][] matrix, char c) {
48+
for (int i = 0; i < matrix.length; i++) {
49+
for (int j = 0; j < matrix[0].length; j++) {
50+
if (matrix[i][j] != 0) {
51+
setPoint(x + j, y + i, c);
52+
}
53+
}
54+
}
55+
}
56+
57+
public int getWidth() {
58+
return width;
59+
}
60+
61+
public int getHeight() {
62+
return height;
63+
}
64+
65+
public char[][] getMatrix() {
66+
return matrix;
67+
}
68+
}
69+
70+
/*
71+
Space (9)
72+
73+
Еще Canvas понадобится два метода, напиши их.
74+
75+
а) метод clear();
76+
77+
Этот метод будет очищать матрицу, чтобы на ней снова можно было рисовать.
78+
79+
Например заменить все символы матрицы на пробелы.
80+
81+
82+
83+
б) метод print();
84+
85+
Этот метод отрисовывает матрицу на экран.
86+
87+
Тут уже ты должен сам разобраться: вывести набор символов не так уж и сложно.
88+
89+
Не забудь добавить пару пустых строк в конце, чтобы матрицы выведенные в разное время не слипались.
90+
91+
92+
93+
94+
95+
Требования:
96+
97+
1. В классе Canvas создай метод clear().
98+
99+
2. Метод clear() должен очищать матрицу.
100+
101+
3. В классе Canvas создай метод print().
102+
103+
4. Метод print() должен отрисовыть матрицу в консоль.
104+
*/

0 commit comments

Comments
 (0)