Κλάση Snow
import gr.aueb.dds.BIO;
class Snow {
private double density; // Snow density: 0 very dense, 1 no snow
private char symbol; // Symbol to use for snowflakes
private int lines; // Lines to draw
// Constructor
Snow(double d, char s, int l) {
density = d;
symbol = s;
lines = l;
}
// Draw the snow
public void draw() {
int i;
for (i = 0; i < lines; i++) {
if (Math.random() > density)
snowFlakes();
BIO.println();
}
}
// Draw a line of random snowflakes
private void snowFlakes() {
int width = 70;
while (width > 0) {
int s = (int)(Math.random() * 10 * density);
DrawChar.space(s);
BIO.print(symbol);
width = width - s - 1;
}
}
// Test the class
public static void main(String args[]) {
Snow s = new Snow(0.1, '*', 4);
s.draw();
}
}