Untitled
unknown
java
3 years ago
1.3 kB
11
Indexable
import java.util.*;
public class LabOneQuestionOne
{
public static void main(String[] args)
{
int finalHours = 0;
int finalMinutes = 0;
int finalSeconds = 0;
Scanner scanner = new Scanner(System.in);
/*Timer[] timers = new Timer[3]; declares an array of Timer
objects and creates an array with a size of 3. */
Timer [] timers = new Timer[3];
int count = 0;
for (int i = 0; i < 3; i++)
{
/*The for loop for is
used to iterate 3 times and create 3 Timer objects. */
System.out.print("Enter the " + (i + 1) + " Timer object: ");
int hours = scanner.nextInt();
int minutes = scanner.nextInt();
int seconds = scanner.nextInt();
timers[i] = new Timer(hours, minutes, seconds);
}
for (Timer t : timers)
{
finalHours += t.getHours();
finalMinutes += t.getMinutes();
finalSeconds += t.getSeconds();
}
System.out.printf("The total number of hours is %d" ,finalHours);
System.out.println();
System.out.printf("The total number of minutes is %d " ,finalMinutes);
System.out.println();
System.out.printf("The total number of seconds is %d",finalSeconds);
}
}
Editor is loading...