Answer to Question #250552 in Java | JSP | JSF for jdot

Question #250552

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


1
Expert's answer
2021-10-12T15:42:08-0400
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();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS