Advertisement
ssunlimited

Calculate The Average Time Sleeping

Apr 28th, 2024
1,022
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class SleepAVG{
  4.    public static void main(String[] args){
  5.       Scanner console = new Scanner(System.in);
  6.       List<Integer> daysSleepTime = new ArrayList<Integer>();
  7.       boolean inProgram = true;
  8.       while(inProgram){
  9.       System.out.println("Sleep how many hours?");
  10.       int hours = console.nextInt();
  11.       System.out.println("Sleep how many minutes?");
  12.       int minutes = console.nextInt();
  13.       System.out.println("In how many days");
  14.       int days = console.nextInt();
  15.       int total = (hours * 60) + minutes;
  16.       System.out.println(total);
  17.       for(int i = 1; i <= days; i++){
  18.          daysSleepTime.add(total);
  19.          }
  20.       System.out.println("End program? Type in true or false.");
  21.       inProgram = !console.nextBoolean();
  22.       }
  23.       int total = 0;
  24.       for(int sleepTime : daysSleepTime) total += sleepTime;
  25.       double sleepAVG = (double) Math.round(total * 100 /daysSleepTime.size()/60) / 100.00;
  26.       System.out.println("Your sleep average is " +
  27.       Math.round(Math.floor(sleepAVG)) + " hours and " + Math.round(
  28.       ((sleepAVG - Math.floor(sleepAVG)) * 60)) + " minutes.");
  29.          }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement