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

This is java, I need a loop that will print basically the indivaul minutes of ea

ID: 3587914 • Letter: T

Question

This is java,

I need a loop that will print basically the indivaul minutes of each players session I have most of the coding done already this is just the last part.

Here is the 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

Here is my code.

import java.io.File;

import java.io.IOException;

import java.nio.file.Files;

import java.nio.file.Paths;

import java.util.ArrayList;

import java.util.Scanner;

public class Student

{

int studentId;

String firstName;

String lastName;

ArrayList<Integer> mins = new ArrayList<>();

public static void studIdAndReadMins(ArrayList<Student> stdList) throws IOException

{

ArrayList<String> minsReadByStudId = new ArrayList<>();

minsReadByStudId = new ArrayList<String>(Files.readAllLines(Paths.get("MinutesPracticed.txt")));

Scanner scan = new Scanner(new File("MinutesPracticed.txt"));

  

for (Student std : stdList) {

for (int i=0;i<minsReadByStudId.size();i++) {

if(i!= 0){

String[] minArray = minsReadByStudId.get(i).split("");

int minutes = Integer.parseInt(minArray[0]);

int id = Integer.parseInt(minArray[1]);

if (std.studentId == id){

std.mins.add(minutes);

}

}

  

}

}

}

  

  

public static void main(String[] args) throws IOException {

ArrayList<Student> stdList = new ArrayList<>();

Scanner scan = new Scanner(new File("Student2017.txt"));

while(scan.hasNext()){

Student stud = new Student();

String[] data = scan.nextLine().split("\|");

stud.studentId = Integer.parseInt(data[0]);

stud.firstName = data[1];

stud.lastName = data[2];

stdList.add(stud);

}

  

  

studIdAndReadMins(stdList);

System.out.println("Sum of Minutes Practiced ");

for (Student std : stdList) {

System.out.print(std.firstName+" "+std.lastName+" ");

int sum = 0;

for(int min:std.mins){

sum+=min;

}

System.out.print(sum+" ");

}

System.out.println(" Individual Minutes Practiced ");

}

}

Explanation / Answer

CODE

Student.java

import java.util.ArrayList;

public class Student {
private String name;
private int id;
ArrayList < Integer > arl = null;

Student() {
arl = new ArrayList < Integer > ();
}

public Student(String name, int id) {
super();
this.name = name;
this.id = id;
arl = new ArrayList < Integer > ();
}

public void addMins(int min) {
arl.add(min);
}

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) {
int mins;
int id;

Scanner sc = null;

Student st[] = new Student[5];

int cnt = 0;
try {
sc = new Scanner(new File("Student2017.txt"));
while (sc.hasNext()) {

String s = sc.next();
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();

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


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 **");
}

}

}

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

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

IF ANY QUERIES REGARDING CODE PLEASE GET BACK TO ME

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