Thursday, September 22, 2016

Processing Delimited String


public class Parse {

    public static void main(String [] args) {
    String arr[];
    String str="E006,Herbert Colanggo,3";
   
    arr=str.split(",");
   
   
   
   
    System.out.println(arr[0]);
    System.out.println(arr[1]);
    }
    
    
}

How To Read A Text File in Java




import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class fileinput {
public static void main(String[] args) throws IOException {
BufferedReader br = null;
String sCurrentLine;

br = new BufferedReader(new FileReader("C:\\Users\\home\\Documents\\Db.txt"));
while ((sCurrentLine = br.readLine()) != null) {
System.out.println(sCurrentLine);
}

}

}

Wednesday, September 21, 2016

TEST CASE 1 - Compro6

Download the files below:

  1. compro6-endterm-project-testcase1.docx
  2. employees.txt

How to compute hour interval between two times? Click here!

How to compute the number of hours between two given times in Java

/**
 * @(#)testcase1.java
 *
 *
 * @author : A. Dichosa
 * @version 1.00 2016/9/21
 */


public class testcase1 {
    public static void main(String [] args) {
    String timein,timeout;
    double time_interval=0; 
        
    timein="8:00";
    timeout="12:00";
    time_interval=GetHourInterval(timein,timeout);
       

    System.out.println(String.format("%.2f",time_interval));    
    }   
    
    /*
     *Description: This method computes the hour interval between two times. It takes two parametes in and out.
     */
    private static double GetHourInterval(String in, String out){
    String timein_arr[];
    String timeout_arr[];
   
    double in_hours=0;
    double out_hours=0;
    double total_hours=0;
   
    timein_arr=in.split(":");
    timeout_arr=out.split(":");
   
    in_hours=Double.parseDouble( timein_arr[0])+ (Double.parseDouble(timein_arr[1])/60);
    out_hours=Double.parseDouble( timeout_arr[0])+ (Double.parseDouble(timeout_arr[1])/60);
    total_hours=out_hours-in_hours;
   
    return total_hours;
   
    }
    
}