Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Each year, elementary school kids must keep track of the number of minutes they

ID: 3587561 • 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

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;
}

}

_________________

TestClass.java

import java.io.File;
import java.io.FileNotFoundException;
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);
}
}
}


//Displaying the each student name and total hours practiced
for (int i = 0; i < cnt; i++) {
System.out.println("Name :" + st[i].getName() + " Sum of Minutes Practices :" + st[i].getTotMinutes());
}


} catch (FileNotFoundException e) {

System.out.println("** File Not Found **");
}

}

}

_________________

Output:

Name :Mary Barnes
Sum of Minutes Practices :411
Name :Mark Brann
Sum of Minutes Practices :710
Name :Katherine Seibold
Sum of Minutes Practices :503
Name :George Harper
Sum of Minutes Practices :745
Name :Gary Smith
Sum of Minutes Practices :583

_____________Could you rate me well.Plz .Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote