Object-Oriented Programming with Java, part I – Exercise 5

Exercise 5

In this exercise you have to add values and variables so that the equation calculates the amount of seconds in a year.


My code

public class SecondsOfTheYear {

    public static void main(String[] args) {   
        // In below an incomplete version of the program. Please complete it!
        
        int daysInYear = 365;
        int hoursInDay = 24;
        int minutesInHour = 60;
        int secondsInMinute = 60;
        int secondsInYear = daysInYear * hoursInDay * minutesInHour *secondsInMinute;

        System.out.println("There are " + secondsInYear + " seconds in a year");
    }

}

Model code

public class SecondsOfTheYear {

    public static void main(String[] args) {   
        // In below an incomplete version of the program. Please complete it!
        
        int daysInYear = 365;
        int hoursInDay = 24;
        int minutesInHour = 60;
        int secondsInMinute = 60;
        int secondsInYear = daysInYear * hoursInDay * minutesInHour *secondsInMinute;

        System.out.println("There are " + secondsInYear + " seconds in a year");
    }

}
Leave a Reply

Your email address will not be published. Required fields are marked *