SECOND AND MINUTES CHALLENGE

Create a method called getDurationString with two parameters, first parameter minutes and 2nd seconds
You should validate that 1st parameter is >=0
  ''        ''            ''         ''    2nd       ''        '' >=0 and <=59
The method should return invalid in the method if either of the above is not true  
If parameters are valid then calculate how many hours minutes and seconds equal the minutes and seconds passed to this method and return that value in the format as "XXh YYm ZZs".
Create a second method of the same name but only one parameter seconds. If it is valid, then calculate how many minutes are in second value and then call the overloaded method passing the correct minutes and seconds calculated so that it can calculate correctly 
Call both methods on the console.

Soln :  
     package com.cnc;
   public class Main {

public static void main(String[] args) {
getDurationString(65,45);
getDurationString(-4,8);
getDurationString(36000);
}
public static void getDurationString(int minutes,int seconds){
if (seconds>=0 && seconds<=59 & minutes>=0){
int hours = minutes/60;
int newMinutes = minutes % 60;
System.out.println(hours+"h:"+newMinutes+"m:"+seconds+"s");
}

else
System.out.println("INVALID");
}
public static void getDurationString(int seconds){
if (seconds>=0){
int minutes = seconds/(60);
int newSeconds = seconds%60;
int newHours = seconds/(60*60);
int newMinutes = minutes/60;
System.out.println(newHours+"h:"+newMinutes+"m:"+newSeconds+"s");
}

else
System.out.println("INVALID");

}
}

Popular posts from this blog

NUMBER PALINDROME CHALLENGE

ENCAPSULATION CHALLENGE

USER INPUT PRINT ORIGINAL,REVERSE ARRAY AND SORTED ARRAY