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
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
public static void studIdAndReadMins(ArrayList
{
ArrayList
minsReadByStudId = new ArrayList
Scanner scan = new Scanner(new File("MinutesPracticed.txt"));
for (Student std : stdList) {
for (int i=0;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 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+"\t"); int sum = 0; for(int min:std.mins){ sum+=min; } System.out.print(sum+" "); } System.out.println(" Individual Minutes Practiced "); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
