-
Notifications
You must be signed in to change notification settings - Fork 0
/
Voldemort.java
40 lines (38 loc) · 1005 Bytes
/
Voldemort.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
import sun.audio.*;
import java.io.*;
import java.util.Random;
class Voldemort
{
public int getRand(int max)
{
Random randomGenerator = new Random();
return randomGenerator.nextInt(max)+1;
}
public synchronized void play(String filename)
{
try
{
InputStream in = new FileInputStream(filename);
AudioStream as = new AudioStream(in);
AudioPlayer.player.start(as);
AudioPlayer.player.join(4000);
AudioPlayer.player.stop();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public synchronized String getTrack(int num)
{
return "sounds/"+Integer.toString(num)+".wav";
}
public static void main(String[] args)
{
Voldemort voldemort = new Voldemort();
int answer =(voldemort.getRand(3));
System.out.println("my answer is: "+answer);
voldemort.play(voldemort.getTrack(0));
voldemort.play(voldemort.getTrack(answer));
}
}