-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNightSky.java
58 lines (49 loc) · 1.34 KB
/
NightSky.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.util.Random;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author kdost
*/
public class NightSky {
private double density;
private int width;
private int height;
private int starsInLastPrint;
public NightSky(double density, int width, int height) {
this.density = density;
this.width = width;
this.height = height;
//this.starsInLastPrint = 0;
}
public NightSky(double density) {
this(density, 20, 10);
}
public NightSky(int width, int height) {
this(0.1, width, height);
}
public void printLine() {
Random random = new Random();
for (int i = 0; i < this.width; i++) {
if (this.density > random.nextDouble()) {
System.out.print("*");
this.starsInLastPrint++;
} else {
System.out.print(" ");
}
}
System.out.println("");
}
public void print() {
this.starsInLastPrint = 0;
for (int i = 0; i < this.height; i++) {
this.printLine();
}
}
public int starsInLastPrint() {
return this.starsInLastPrint;
}
}