Learning coding means GreatToCode Be more than a Coder ! Greattocode , Join GreatToCode Community,1000+ Students Trusted On Us .If You want to learn coding, Then GreatToCode Help You.No matter what It Takes !


CODE YOUR WAY TO A MORE FULFILLING And HIGHER PAYING CAREER IN TECH, START CODING FOR FREE Camp With GreatToCode - Join the Thousands learning to code with GreatToCode
Interactive online coding classes for at-home learning with GreatToCode . Try ₹Free Per Month Coding Classes With The Top Teachers . sleep management software In Java.

sleep management software In Java.

Let's create a simple sleep management software in Java. This software will allow you to track your sleep duration, set sleep goals, and view sleep statistics. Here's an example implementation to get you started:

```java
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;

class SleepRecord {
    private LocalDateTime startTime;
    private LocalDateTime endTime;

    public SleepRecord(LocalDateTime startTime, LocalDateTime endTime) {
        this.startTime = startTime;
        this.endTime = endTime;
    }

    public LocalDateTime getStartTime() {
        return startTime;
    }

    public LocalDateTime getEndTime() {
        return endTime;
    }

    public Duration getSleepDuration() {
        return Duration.between(startTime, endTime);
    }
}

public class SleepManager {
    private SleepRecord currentSleepRecord;
    private Duration sleepGoal;
    private int totalSleepRecords;
    private Duration totalSleepDuration;

    public SleepManager() {
        this.currentSleepRecord = null;
        this.sleepGoal = Duration.ZERO;
        this.totalSleepRecords = 0;
        this.totalSleepDuration = Duration.ZERO;
    }

    public void setSleepGoal(Duration sleepGoal) {
        this.sleepGoal = sleepGoal;
        System.out.println("Sleep goal set: " + formatDuration(sleepGoal));
    }

    public void startSleep() {
        if (currentSleepRecord == null) {
            LocalDateTime startTime = LocalDateTime.now();
            currentSleepRecord = new SleepRecord(startTime, null);
            System.out.println("Sleep started at " + formatDateTime(startTime));
        } else {
            System.out.println("Sleep already in progress.");
        }
    }

    public void endSleep() {
        if (currentSleepRecord != null) {
            LocalDateTime endTime = LocalDateTime.now();
            currentSleepRecord = new SleepRecord(currentSleepRecord.getStartTime(), endTime);
            Duration sleepDuration = currentSleepRecord.getSleepDuration();
            totalSleepRecords++;
            totalSleepDuration = totalSleepDuration.plus(sleepDuration);
            System.out.println("Sleep ended at " + formatDateTime(endTime));
            System.out.println("Sleep duration: " + formatDuration(sleepDuration));
            currentSleepRecord = null;
        } else {
            System.out.println("No sleep in progress.");
        }
    }

    public void viewSleepStatistics() {
        System.out.println("Sleep Statistics:");
        System.out.println("Total sleep records: " + totalSleepRecords);
        System.out.println("Total sleep duration: " + formatDuration(totalSleepDuration));
        System.out.println("Sleep goal: " + formatDuration(sleepGoal));
    }

    private String formatDateTime(LocalDateTime dateTime) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return dateTime.format(formatter);
    }

    private String formatDuration(Duration duration) {
        long hours = duration.toHours();
        long minutes = duration.toMinutesPart();
        return String.format("%02d:%02d", hours, minutes);
    }

    public static void main(String[] args) {
        SleepManager sleepManager = new SleepManager();
        Scanner scanner = new Scanner(System.in);

        while (true) {
            System.out.println("Sleep Manager");
            System.out.println("1. Set Sleep Goal");
            System.out.println("2. Start Sleep");
            System.out.println("3. End Sleep");
            System.out.println("4. View Sleep Statistics");
            System.out.println("5. Exit");
            System.out.print("Enter your choice: ");
            int choice = scanner.nextInt();
            scanner.nextLine(); // Consume newline

            switch (choice) {
                case 1:
                    System.out.print("Enter sleep goal (in hours and minutes, e.g., 7:30): ");
                    String sleepGoalInput = scanner.nextLine();

Post a Comment

0 Comments

•Give The opportunity to your child with GreatToCode Kid's • Online Coding Classes for Your Kid • Introduce Your kid To the world's of coding
•Fuel You Career with our 100+ Hiring Partners, Advance Your Career in Tech with GreatToCode. •Join The Largest Tech and coding Community and Fast Forward Your career with GreatToCode. •10000+ Learner's+ 90 % placement Guarantee. • Learning Coding is Better with the GreatToCode community .
•Greattocode Kid's •GreatToCode Career •GreatToCode Interview •GreatToCode Professional •GreatToCode for schools •GreatToCode For colleges •GreatToCods For Businesses.
Are you ready to join the millions of people learning to code? GreatToCode Pass is your one-stop-shop to get access to 1000+ courses, top-notch support, and successful job placement. What are you waiting for? Sign up now and get your future in motion with GreatToCode Pass.