Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package DPM;
- import java.io.*;
- public class Main {
- private static final String FILE_PATH = "D://Coding/Java/Softuni/Java Fundamentals 2016/3. Java-Streams/users.txt";
- private static final String SAVE_PATH = "D://Coding/Java/Softuni/Java Fundamentals 2016/3. Java-Streams/res.txt";
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new FileReader(FILE_PATH));
- BufferedWriter output = new BufferedWriter(new FileWriter(SAVE_PATH));
- String line;
- while ((line = reader.readLine()) != null) {
- String[] playerLine = line.split(" ");
- String user = playerLine[0];
- int minutes = 0;
- int totalTime = 0;
- for (int i = 1; i < playerLine.length; i++) {
- String column = playerLine[i];
- String[] logTime = column.split(":");
- int hours = Integer.parseInt(logTime[0]);
- int min = Integer.parseInt(logTime[1]);
- int totalMin = min +(hours * 60);
- minutes += totalMin;
- totalTime += totalMin;
- }
- int minInDay = 1440;
- int days = minutes/ minInDay;
- minutes %= minInDay;
- int hours = minutes /60;
- minutes %= 60;
- String outputFor = String.format("%s %d (%d days, %d hours, %d minutes)\r\n", user, totalTime, days, hours, minutes);
- output.write(outputFor);
- }
- reader.close();
- output.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement