自顶向下:类比于 计划经济,需求变化时候显的很尴尬,需要变动很多东西
自底向上:自适应变化
在开发过程中,混合使用多种设计风格
package NO3;
import java.util.Scanner;
class cell{
private int x;
private int y;
private int width;
private int height;
public cell(int x, int y, int width, int height){
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public void draw(char[][] a){
/*for(int i = x; i < x + width ;i++){
a[y][i] = '$';
}
for(int i = x; i < x + width ;i++)
a[y + height-1][i] = '$';
for(int i = y + 1;i < y + height; i++)
a[i][x] = '$';
for(int i = 0; i < y + height;i++)
a[i][x + width-1 ] = '$';
*/
for(int i = 0; i < width; i++){
a[y][x + i] = '$';
a[y + height-1][x + i ] = '$';
}
for(int i = 0; i < height;i++){
a[y+i][x] = '$';
a[y+i][x + width -1] = '$';
}
}
}
public class Test04 {
public static void main(String[] args) {
// TODO Auto-generated method stub
char[][] cache = new char[20][50];
Scanner input = new Scanner(System.in);
int line = input.nextInt();
int row = input.nextInt();
//int width = input.nextInt();
//int height = input.nextInt();
for(int i = 0; i < line ;i++)
for(int j = 0; j < row;j++){
cell c1 = new cell(j*(5- 1) , i*(4 - 1), 5, 4);
c1.draw(cache);
}
print(cache);
}
private static void print(char[][] cache) {
// TODO Auto-generated method stub
for(int i = 0; i < cache.length; i++){
for(int j = 0; j < cache[i].length; j++){
if(cache[i][j] == 0)
System.out.print(" ");
else
System.out.print(cache[i][j]);
}
System.out.println();
}
}
}
结果:
3
4
$$$$$$$$$$$$$$$$$
$ $ $ $ $
$ $ $ $ $
$$$$$$$$$$$$$$$$$
$ $ $ $ $
$ $ $ $ $
$$$$$$$$$$$$$$$$$
$ $ $ $ $
$ $ $ $ $
$$$$$$$$$$$$$$$$$