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
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;
}
}
* @(#)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;
}
}
Thursday, September 15, 2016
A Simple CRUD using Laravel 5.2 Framework
Steps to Install the Application to a Remote Server
- Decompress and upload all files to target directory gregorytest.rar.
- Import the database gregorydata.sql
- Copy all files inside
/publicfolder into the default project folder. - Remove folder
/public. - Edit file
./index.php, add this lineuse Illuminate\Contracts\Http\Kernel;to the topmost line.On the same file, look for linerequire __DIR__.'/../bootstrap/autoload.php';and replace it withrequire __DIR__."/bootstrap/autoload.php";Also, line$app = require_once __DIR__.'/../bootstrap/app.php';with$app = require_once __DIR__."/bootstrap/app.php";Lastly line$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);with$kernel = $app->make(Kernel::class); - Edit file
/config/bootstrap.phpand locate line'url' => env('APP_URL', 'http://localhost'),and replace it with'url' => env('APP_URL', 'http://[you_project_folder]/'), - Finally, .env file needs editing alsoAPP_ENV=localAPP_DEBUG=trueAPP_KEY=base64:eegf6eODvThzJiyXWMp3Bh7OLUbgqOJhQ16kZcXr9qw=APP_URL=http://[project_directory]DB_CONNECTION=mysqlDB_HOST=sql6.freemysqlhosting.netDB_PORT=3306DB_DATABASE=sql6135311DB_USERNAME=sql6135311DB_PASSWORD=3te5D9vhTU
- Enjoy!
Tuesday, September 13, 2016
Java - Files and I/O
Important: Use the comment section below for questions. Use the format {your fullname}: {question}
The java.io package contains nearly every class you might ever need to perform input and output (I/O) in Java. All these streams represent an input source and an output destination. The stream in the java.io package supports many data such as primitives, Object, localized characters, etc.
Stream
InPutStream: The InputStream is used to read data from a source.
OutPutStream: the OutputStream is used for writing data to a destination.
A stream can be defined as a sequence of data. there are two kinds of Streams

Dissecting the Program
What the program does is just to copy the content of file input.txt and write it down to output.txt.
CHECK YOURSELF
What would be written to file output.txt if we run these statements individually?
The java.io package contains nearly every class you might ever need to perform input and output (I/O) in Java. All these streams represent an input source and an output destination. The stream in the java.io package supports many data such as primitives, Object, localized characters, etc.
Stream
InPutStream: The InputStream is used to read data from a source.
OutPutStream: the OutputStream is used for writing data to a destination.
A stream can be defined as a sequence of data. there are two kinds of Streams

Java provides strong but flexible support for I/O related to Files and networks but this tutorial covers very basic functionality related to streams and I/O. We would see most commonly used example one by one:
Byte Streams
Java byte streams are used to perform input and output of 8-bit bytes (for reference check the table of 8-bit characters). Though there are many classes related to byte streams but the most frequently used classes are , FileInputStream and FileOutputStream. Following is an example which makes use of these two classes to copy an input file into an output file:
Byte Streams
Java byte streams are used to perform input and output of 8-bit bytes (for reference check the table of 8-bit characters). Though there are many classes related to byte streams but the most frequently used classes are , FileInputStream and FileOutputStream. Following is an example which makes use of these two classes to copy an input file into an output file:
import java.io.*; public class CopyFile { public static void main(String args[]) throws IOException { FileInputStream in = null; FileOutputStream out = null; try { in = new FileInputStream("input.txt"); out = new FileOutputStream("output.txt"); int c; while ((c = in.read()) != -1) { out.write(c); } }finally { if (in != null) { in.close(); } if (out != null) { out.close(); } } } }Now let's have a file input.txt with the following content:
This is test for copy file.As a next step, compile above program and execute it, which will result in creating output.txt file with the same content as we have in input.txt.
Dissecting the Program
What the program does is just to copy the content of file input.txt and write it down to output.txt.
What would be written to file output.txt if we run these statements individually?
- out.write(078);
- out.write(079);
- out.write(095);
- out.write(080);
- out.write(065);
- out.write(073);
- out.write(078);
- out.write(095);
- out.write(078);
- out.write(079);
- out.write(095);
- out.write(071);
- out.write(065);
- out.write(073);
- out.write(078);
Tuesday, July 12, 2016
Solus and Gnome - COMPRO6
Lab Activity #3:
To those who did not make it in time last session's activity, you need to comply by submitting the attached source code to email adichosa@gmail.com with email subject "Act3-Late-[Your Section]-[Fullname]". This should be sent to my email not later than 12PM for Solus and 3PM for Gnome.
-------------------------------------------------
Lab Activity #4:
Problem:
Write a program to accept five integers from the keyboard and store them to array arr. Process the array and display the sum, average, min and max.
Sample Output:
Enter element 1: 3
Enter element 2: 6
Enter element 3: 2
Enter element 4: 10
Enter element 5: 31
Processing...
Sum: 56
Average: 11.2
Min: 2
Max: 31
Important: Email to adichosa@gmail.com with subject "Act4-[Your Section]-[Your name]".
Very very very ... very IMPORTANT:
I am appointing Mr. Togle of Solus and Mr. Pedrajas of Gnome to jot-down the names of those who are making loud noises during the session. Necessary deductions to Activity #4 will be imposed to those who are in the list.
To those who did not make it in time last session's activity, you need to comply by submitting the attached source code to email adichosa@gmail.com with email subject "Act3-Late-[Your Section]-[Fullname]". This should be sent to my email not later than 12PM for Solus and 3PM for Gnome.
-------------------------------------------------
Lab Activity #4:
Problem:
Write a program to accept five integers from the keyboard and store them to array arr. Process the array and display the sum, average, min and max.
Sample Output:
Enter element 1: 3
Enter element 2: 6
Enter element 3: 2
Enter element 4: 10
Enter element 5: 31
Processing...
Sum: 56
Average: 11.2
Min: 2
Max: 31
Important: Email to adichosa@gmail.com with subject "Act4-[Your Section]-[Your name]".
Very very very ... very IMPORTANT:
I am appointing Mr. Togle of Solus and Mr. Pedrajas of Gnome to jot-down the names of those who are making loud noises during the session. Necessary deductions to Activity #4 will be imposed to those who are in the list.
Subscribe to:
Posts (Atom)