-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathNightSky.java
59 lines (52 loc) · 1.36 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
59
import java.util.Random;
/**
*
* @author giuseppedesantis
*/
public class NightSky {
private double density;
private int width;
private int height;
private int starsInLastPrint = 0;
public NightSky(double density){
this.density = density;
this.width = 20;
this.height = 10;
}
public NightSky(int width, int height){
this.density = 0.1;
this.width = width;
this.height = height;
}
public NightSky(double density, int width, int height){
this.density = density;
this.width = width;
this.height = height;
}
public void printLine(){
Random random = new Random();
String line = "";
String letters = " *";
String symbol = "";
for(int i = 0; i < this.width; i ++){
double probability = random.nextDouble();
if(probability > this.density){
symbol = " ";
}else{
symbol = "*";
this.starsInLastPrint += 1;
}
line += symbol;
}
System.out.println(line);
}
public void print(){
this.starsInLastPrint = 0;
for(int i = 0; i < this.height; i++){
this.printLine();
}
}
public int starsInLastPrint(){
return this.starsInLastPrint;
}
}