Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class SleepAVG{
- public static void main(String[] args){
- try{
- Scanner console = new Scanner(new File ("Sleep Tracker.txt"));
- List<Integer> daysSleepTime = new ArrayList<Integer>();
- while(console.hasNextInt()){
- int hours = console.nextInt();
- int minutes = console.nextInt();
- int total = (hours * 60) + minutes;
- daysSleepTime.add(total);
- }
- int total = 0;
- for(int sleepTime : daysSleepTime) total += sleepTime;
- double sleepAVG = (double) Math.round(total * 100 /daysSleepTime.size()/60) / 100.00;
- System.out.println("Your sleep average is " +
- Math.round(Math.floor(sleepAVG)) + " hours and " + Math.round(
- ((sleepAVG - Math.floor(sleepAVG)) * 60)) + " minutes.");
- }
- catch (FileNotFoundException e) {
- System.out.println("An error occurred.");
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement