This is java Each year, elementary school kids must keep track of the number of
ID: 3587868 • Letter: T
Question
This is java
Each year, elementary school kids must keep track of the number of minutes they practice their band instrument each week. This ensures that they continue progressing with their instrument and become musicians. In this program, you are to create an application that shows the sum total of the minutes practiced by each student. There are two files in which you are to read. The first one, Student2017.txt contains all the students. The second one, MinutesPracticed.txt contains the minutes practiced and the student id. You are to create a Student class that contains an ArrayList of all the minutes read for each student. The end user should be able to print out the individual minutes read by a student and the sum total of the minutes ready by a student. An example of output might be like this:
-----------------------------------------------------
Sum of Minutes Practiced
Name Minutes Practiced
Sammy Hagger 65
Nick Jonas 1001
…
------------------------------------------------------
Individual Minutes Practiced
Name Minutes Practiced
Sammy Hagger 35
Sammy Hagger 30
Nick Jonas 500
Nick Jonas 5001
…
------------------------------------------------------
Student2017.txt
1|Mary|Barnes
2|Mark|Brann
3|Katherine|Seibold
4|George|Harper
5|Gary|Smith
MinutesPracticed.txt
MinutesRead Person
46 4
36 2
15 4
17 1
39 5
39 1
48 3
36 5
46 5
21 4
20 4
31 4
42 3
45 5
37 1
45 2
50 5
25 2
37 4
12 1
41 3
25 5
47 3
48 1
27 3
30 2
40 4
38 3
22 2
34 2
22 4
29 1
10 1
42 4
36 2
24 3
31 2
50 1
32 3
28 4
45 2
47 4
35 1
46 3
15 5
45 4
10 2
14 5
25 4
15 1
34 2
32 2
12 3
21 3
10 1
26 2
48 1
45 2
40 4
33 5
40 5
13 1
47 5
45 2
22 5
42 5
50 3
31 3
44 4
25 4
50 4
26 3
32 4
38 4
44 5
27 1
45 2
17 5
45 2
49 2
38 4
21 1
22 5
23 5
16 4
18 3
43 4
39 2
23 5
36 2
Explanation / Answer
/***********************************Musicians.java*************************************/
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* The Class Musicians.
*/
public class Musicians {
/**
* The main method.
*
* @param args the arguments
*/
public static void main(String[] args) {
// variable declaration
BufferedReader br = null;
FileReader fr = null;
// storing student name and id
Map<String, String> student = new HashMap<>();
// Storing name and minutes
Map<String, Integer> minutesRead = new HashMap<>();
try {
// reading student file
fr = new FileReader("Student2017.txt");
br = new BufferedReader(fr);
String record;
while ((record = br.readLine()) != null) {
String[] st = record.split("\|");
student.put(st[0], st[1] + " " + st[2]);
}
fr.close();
br.close();
// reading minutes Practiced file
fr = new FileReader("MinutesPracticed.txt");
br = new BufferedReader(fr);
while ((record = br.readLine()) != null) {
String[] st = record.split(" ");
String name = student.get(st[1]);
Integer minute = minutesRead.get(name);
Integer minutes = Integer.parseInt(st[0]);
if (minute != null) {
minutesRead.put(name, minute + minutes);
} else {
minutesRead.put(name, minutes);
}
}
// Printing name and minutes practiced
System.out.println("Name Minutes Practiced");
for (Map.Entry<String, Integer> entry : minutesRead.entrySet()) {
System.out.println(entry.getKey() + " " + entry.getValue());
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)
br.close();
if (fr != null)
fr.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
/********************************output*************************************/
Name Minutes Practiced
Gary Smith 583
Mark Brann 710
Mary Barnes 411
Katherine Seibold 503
George Harper 745
/**************************************Student2017.txt************************************/
1|Mary|Barnes
2|Mark|Brann
3|Katherine|Seibold
4|George|Harper
5|Gary|Smith
/**********************************MinutesPracticed.txt**************************/
46 4
36 2
15 4
17 1
39 5
39 1
48 3
36 5
46 5
21 4
20 4
31 4
42 3
45 5
37 1
45 2
50 5
25 2
37 4
12 1
41 3
25 5
47 3
48 1
27 3
30 2
40 4
38 3
22 2
34 2
22 4
29 1
10 1
42 4
36 2
24 3
31 2
50 1
32 3
28 4
45 2
47 4
35 1
46 3
15 5
45 4
10 2
14 5
25 4
15 1
34 2
32 2
12 3
21 3
10 1
26 2
48 1
45 2
40 4
33 5
40 5
13 1
47 5
45 2
22 5
42 5
50 3
31 3
44 4
25 4
50 4
26 3
32 4
38 4
44 5
27 1
45 2
17 5
45 2
49 2
38 4
21 1
22 5
23 5
16 4
18 3
43 4
39 2
23 5
36 2
Thanks a lot. Please let me know if you have any doubt.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.