Each year, elementary school kids must keep track of the number of minutes they
ID: 3587824 • Letter: E
Question
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
Note: I think this is perfect ..plz let me know if u need any modifications in this..thank you..plz change the rating....as i put my effort in this...thank you...
__________________
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
_____________
Student.java
import java.util.ArrayList;
public class Student {
// Declaring instance variables
private String name;
private int id;
ArrayList < Integer > arl = null;
// Zero argumented constructor
Student() {
arl = new ArrayList < Integer > ();
}
// Parameterized constructor
public Student(String name, int id) {
super();
this.name = name;
this.id = id;
arl = new ArrayList < Integer > ();
}
// This method will add the minutes to the ArrayList
public void addMins(int min) {
arl.add(min);
}
// Setters and getters
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getTotMinutes() {
int tot = 0;
for (int i: arl) {
tot += i;
}
return tot;
}
public ArrayList < Integer > getArl() {
return arl;
}
}
______________________
TestClass.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class TestClass {
public static void main(String[] args) {
//Declaring variables
int mins;
int id;
Scanner sc = null;
//Creating an array of Student class objects
Student st[] = new Student[5];
//Opening the file and read student names and ID
int cnt = 0;
try {
sc = new Scanner(new File("Student2017.txt"));
while (sc.hasNext()) {
String s = sc.next();
//System.out.println(s);
int x = s.indexOf('|');
String sep1 = s.substring(0, x);
int y = s.lastIndexOf('|');
String name1 = s.substring(x + 1, y);
String name2 = s.substring(y + 1);
String name = name1 + " " + name2;
st[cnt] = new Student(name, new Integer(Integer.parseInt((sep1))));
cnt++;
}
sc.close();
//Opening the file and read practiced hours and ID
sc = new Scanner(new File("MinutesPracticed.txt"));
while (sc.hasNext()) {
mins = sc.nextInt();
id = sc.nextInt();
for (int i = 0; i < cnt; i++) {
if (st[i].getId() == id) {
st[i].addMins(mins);
// System.out.println(st[id].getName()+" ");
}
}
}
//Displaying the each student name and individual minutes practiced
for (int i = 0; i < cnt; i++) {
System.out.println("-----------------------");
System.out.println("Individual Minutes Practiced");
System.out.println("Name Minutes Practiced");
ArrayList < Integer > ar = st[i].getArl();
for (int j = 0; j < ar.size(); j++) {
System.out.println(st[i].getName() + " " + ar.get(j));
}
}
//Displaying the each student name and total hours practiced
for (int i = 0; i < cnt; i++) {
System.out.println("-------------------------------");
System.out.println("Sum of Minutes Practiced");
System.out.println("Name Minutes Practiced");
System.out.println(st[i].getName() + " " + st[i].getTotMinutes());
}
} catch (FileNotFoundException e) {
System.out.println("** File Not Found **");
}
}
}
_____________________
Output:
-----------------------
Individual Minutes Practiced
Name Minutes Practiced
Mary Barnes 17
Mary Barnes 39
Mary Barnes 37
Mary Barnes 12
Mary Barnes 48
Mary Barnes 29
Mary Barnes 10
Mary Barnes 50
Mary Barnes 35
Mary Barnes 15
Mary Barnes 10
Mary Barnes 48
Mary Barnes 13
Mary Barnes 27
Mary Barnes 21
-----------------------
Individual Minutes Practiced
Name Minutes Practiced
Mark Brann 36
Mark Brann 45
Mark Brann 25
Mark Brann 30
Mark Brann 22
Mark Brann 34
Mark Brann 36
Mark Brann 31
Mark Brann 45
Mark Brann 10
Mark Brann 34
Mark Brann 32
Mark Brann 26
Mark Brann 45
Mark Brann 45
Mark Brann 45
Mark Brann 45
Mark Brann 49
Mark Brann 39
Mark Brann 36
-----------------------
Individual Minutes Practiced
Name Minutes Practiced
Katherine Seibold 48
Katherine Seibold 42
Katherine Seibold 41
Katherine Seibold 47
Katherine Seibold 27
Katherine Seibold 38
Katherine Seibold 24
Katherine Seibold 32
Katherine Seibold 46
Katherine Seibold 12
Katherine Seibold 21
Katherine Seibold 50
Katherine Seibold 31
Katherine Seibold 26
Katherine Seibold 18
-----------------------
Individual Minutes Practiced
Name Minutes Practiced
George Harper 46
George Harper 15
George Harper 21
George Harper 20
George Harper 31
George Harper 37
George Harper 40
George Harper 22
George Harper 42
George Harper 28
George Harper 47
George Harper 45
George Harper 25
George Harper 40
George Harper 44
George Harper 25
George Harper 50
George Harper 32
George Harper 38
George Harper 38
George Harper 16
George Harper 43
-----------------------
Individual Minutes Practiced
Name Minutes Practiced
Gary Smith 39
Gary Smith 36
Gary Smith 46
Gary Smith 45
Gary Smith 50
Gary Smith 25
Gary Smith 15
Gary Smith 14
Gary Smith 33
Gary Smith 40
Gary Smith 47
Gary Smith 22
Gary Smith 42
Gary Smith 44
Gary Smith 17
Gary Smith 22
Gary Smith 23
Gary Smith 23
-------------------------------
Sum of Minutes Practiced
Name Minutes Practiced
Mary Barnes 411
-------------------------------
Sum of Minutes Practiced
Name Minutes Practiced
Mark Brann 710
-------------------------------
Sum of Minutes Practiced
Name Minutes Practiced
Katherine Seibold 503
-------------------------------
Sum of Minutes Practiced
Name Minutes Practiced
George Harper 745
-------------------------------
Sum of Minutes Practiced
Name Minutes Practiced
Gary Smith 583
_____________Could you rate me well.Plz .Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.