-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinalProject.java
More file actions
98 lines (88 loc) · 2.3 KB
/
Copy pathFinalProject.java
File metadata and controls
98 lines (88 loc) · 2.3 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import java.io.*;
import jm.music.data.*;
import jm.JMC;
import jm.util.*;
import java.util.*;
public class FinalProject implements JMC
{
public static void main(String[] args)
{
Scanner inScan = null;
String[] year = new String [10];
int[] mortality= new int[10];
try
{
BufferedReader b = new BufferedReader(new FileReader("mortality.txt"));
inScan = new Scanner(b);
int yearIndex=0;
while (inScan.hasNextLine())
{
String line = inScan.nextLine();
String[] cols = line.split(",");
year[yearIndex]=cols[0];
mortality[yearIndex] = Integer.parseInt(cols[1]);
yearIndex++;
}
inScan.close();
}
catch(FileNotFoundException e)
{
System.out.println("There was an error reading the file");
}
try
{
int sum =0;
for (int i = 0; i < mortality.length; i++)
{
sum += mortality[i];
}
int avg = sum / mortality.length;
String str = "Mortality avg: "+ avg +"\n";
BufferedWriter writer = new BufferedWriter(new FileWriter("mortalityOut.txt"));
writer.write(str);
writer.close();
}
catch(IOException i)
{
System.out.println("There was an error writing the file");
}
int sum = 0;
for (int i = 0; i < mortality.length; i++)
{
sum = sum + mortality[i];
}
int avg = sum / mortality.length;
scale(mortality);
Play.midi(makePhrase(mortality, avg));
}
public static void scale(int a[])
{
int sum = 0;
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
int myRange = 50;
int range;
for (int i = 0; i < a.length; i++)
{
if (a[i] < min)
min = a[i];
if (a[i] > max)
max = a[i];
}
range = max - min;
for (int i = 0; i < a.length; i++)
a[i] = ((50 + (a[i] - min))*myRange/range) - 128;
}
public static Phrase makePhrase(int a[], int avg)
{
Phrase notes = new Phrase(0.0);
notes.setInstrument(GOBLIN);
notes.setTempo(avg);
for (int i = 0; i < a.length; i++)
{
notes.addNote(new Note(a[i],HN));
notes.addNote(new Note(REST,QN));
}
return notes;
}
}