Create a Time class and initialize it with hours and minutes.
1- Make a method displayTime which should print the time in hh:mm:ss format.
2- Make a method DisplayMinute which should display the total minutes in the Time. E.g.- (1 hr 2 min) should display 62 minutes
import java.util.Scanner;
class Time {
private int hours;
private int minutes;
public Time(int hours, int minutes) {
this.hours = hours;
this.minutes = minutes;
}
public void displayTime() {
System.out.printf("%02d:%02d:%02d\n",this.hours,this.minutes,0);
}
public void displayMinute() {
this.minutes+=this.hours*60;
System.out.printf("%d minutes\n",this.minutes);
}
}
public class App {
public static void main(String[] args) {
Scanner keyBoard = new Scanner(System.in);
System.out.print("Enter number of hours: ");
int hours = keyBoard.nextInt();
System.out.print("Enter number of minutes: ");
int minutes = keyBoard.nextInt();
Time time=new Time(hours, minutes);
time.displayTime();
time.displayMinute();
keyBoard.close();
}
}
Comments
Leave a comment