import java.awt.*; // make the graphics libraries available
import java.applet.*; // make the applet libraries available
// THis program converts a given number of seconds
// into the equivalent hours, minutes and seconds .
// For example given 5000 seconds this is converted
// into 1 hour 23 minutes and 2 seconds
// You should note that there are 60 seconds in one
// minute and 60 minutes in one hour so there are
// 60 x 60 = 3600 seconds in one hour.
// The operator '%' is the remainder operator i.e.
// 14 % 5 = 4.
//
public class SecondsConversion extends Applet // make a new applet
{
private int seconds; // declare an integer variable to hold the number of seconds
private int hours; // declare an integer variable for the hours
// declare an integer variable for the minutes
public void paint(Graphics g)
{
seconds = 17000; // assign seconds the value 17000
hours = seconds / 3600; // how many hours are there in
// this many seconds?
g.drawString(seconds + " seconds converts to " + hours + " hour(s) ", 20, 20);
// now calculate how many seconds are not this number of hours
// store the result in seconds i.e. overwrite the current value in seconds
// now calculate how many minutes in this number of seconds
// store the result in minutes
// now calculate how many seconds are not in this number of minutes
// store the result in seconds
// now print out the number of hours, minutes and seconds.
}
} |