Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class SleepAVG{
- public static void main(String[] args){
- Scanner console = new Scanner(System.in);
- List<Integer> daysSleepTime = new ArrayList<Integer>();
- boolean inProgram = true;
- while(inProgram){
- System.out.println("Sleep how many hours?");
- int hours = console.nextInt();
- System.out.println("Sleep how many minutes?");
- int minutes = console.nextInt();
- System.out.println("In how many days");
- int days = console.nextInt();
- int total = (hours * 60) + minutes;
- System.out.println(total);
- for(int i = 1; i <= days; i++){
- daysSleepTime.add(total);
- }
- System.out.println("End program? Type in true or false.");
- inProgram = !console.nextBoolean();
- }
- 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.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement